forked from CodeEditApp/CodeEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!--- IMPORTANT: If this PR addresses multiple unrelated issues, it will be closed until separated. --> ### Description Replaces `STTextView` with a custom TextView implementation. Creates a new `TextView` and `TextViewController` classes that manage rendering text, handling text input, and keybinds. `TextViewController` replaces the `STTextViewController` class, connecting existing TextFormation classes, syntax highlighting, and other existing text view extensions. ### Related Issues * closes CodeEditApp#208 * closes #195 * closes CodeEditApp#184 * closes CodeEditApp#57 ### Checklist TextView TODOs: - [X] load text - [X] render text - [X] scroll - [X] wrap text - [X] resize - [x] syntax highlighting - [x] cursor - [x] edit text - [x] isEditable - [x] Insert - [x] Delete - [x] Delete line - [x] Delete word - [x] Delete character - [x] Delete across lines - [x] Paste - [x] [Marked Text](https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html#//apple_ref/doc/uid/TP40009459-CH3-SW26) - [x] Line Numbers - [x] Select text - [x] Copy - [x] Multiple cursors - [x] Keyboard navigation - [x] Arrow keys - [x] Command & control arrow keys - [ ] Page up and down - [x] Tab widths & indents - [x] Live parameter updating - [x] Undo/redo - [x] Sync system appearance - [x] Highlight brackets - [x] TextFormation integration - [ ] ~MacOS Sonoma cursor~ Leaving for future PR. Will require rework of cursor view system. - [x] Update text from SwiftUI Binding (two-way binding) - [x] Accessibility - [x] Drag and Drop (bad, will need a rework but okay for now) -- - [x] I read and understood the [contributing guide](https://github.com/CodeEditApp/CodeEdit/blob/main/CONTRIBUTING.md) as well as the [code of conduct](https://github.com/CodeEditApp/CodeEdit/blob/main/CODE_OF_CONDUCT.md) - [x] The issues this PR addresses are related to each other - [x] My changes generate no new warnings - [x] My code builds and runs on my machine - [x] My changes are all related to the related issue above - [x] I documented my code ### Screenshots `// TODO` --------- Co-authored-by: Austin Condiff <austin.condiff@gmail.com> Co-authored-by: Wesley de Groot <email@wesleydegroot.nl>
- Loading branch information
1 parent
cb7bfbf
commit 40d8e88
Showing
90 changed files
with
7,290 additions
and
1,017 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
Sources/CodeEditInputView/Documentation.docc/Documentation.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# ``CodeEditInputView`` | ||
|
||
A text editor designed to edit code documents. | ||
|
||
## Overview | ||
|
||
A text editor specialized for displaying and editing code documents. Features include basic text editing, extremely fast initial layout, support for handling large documents, customization options for code documents. | ||
|
||
> This package contains a text view suitable for replacing `NSTextView` in some, ***specific*** cases. If you want a text view that can handle things like: left-to-right layout, custom layout elements, or feature parity with the system text view, consider using [STTextView](https://github.com/krzyzanowskim/STTextView) or [NSTextView](https://developer.apple.com/documentation/appkit/nstextview). The ``TextView`` exported by this library is designed to lay out documents made up of lines of text. However, it does not attempt to reason about the contents of the document. If you're looking to edit *source code* (indentation, syntax highlighting) consider using the parent library [CodeEditTextView](https://github.com/CodeEditApp/CodeEditTextView). | ||
The ``TextView`` class is an `NSView` subclass that can be embedded in a scroll view or used standalone. It parses and renders lines of a document and handles mouse and keyboard events for text editing. It also renders styled strings for use cases like syntax highlighting. | ||
|
||
## Topics | ||
|
||
### Text View | ||
|
||
- ``TextView`` | ||
- ``CEUndoManager`` | ||
|
||
### Text Layout | ||
|
||
- ``TextLayoutManager`` | ||
- ``TextLine`` | ||
- ``LineFragment`` | ||
|
||
### Text Selection | ||
|
||
- ``TextSelectionManager`` | ||
- ``TextSelectionManager/TextSelection`` | ||
- ``CursorView`` | ||
|
||
### Supporting Types | ||
|
||
- ``TextLineStorage`` | ||
- ``HorizontalEdgeInsets`` | ||
- ``LineEnding`` | ||
- ``LineBreakStrategy`` |
14 changes: 14 additions & 0 deletions
14
Sources/CodeEditInputView/Extensions/NSRange+isEmpty.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// NSRange+isEmpty.swift | ||
// | ||
// | ||
// Created by Khan Winter on 8/23/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension NSRange { | ||
var isEmpty: Bool { | ||
length == 0 | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
Sources/CodeEditInputView/Extensions/NSTextStorage+getLine.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// | ||
// NSTextStorage+getLine.swift | ||
// | ||
// | ||
// Created by Khan Winter on 9/3/23. | ||
// | ||
|
||
import AppKit | ||
|
||
extension NSString { | ||
func getNextLine(startingAt location: Int) -> NSRange? { | ||
let range = NSRange(location: location, length: 0) | ||
var end: Int = NSNotFound | ||
var contentsEnd: Int = NSNotFound | ||
self.getLineStart(nil, end: &end, contentsEnd: &contentsEnd, for: range) | ||
if end != NSNotFound && contentsEnd != NSNotFound && end != contentsEnd { | ||
return NSRange(location: contentsEnd, length: end - contentsEnd) | ||
} else { | ||
return nil | ||
} | ||
} | ||
} | ||
|
||
extension NSTextStorage { | ||
func getNextLine(startingAt location: Int) -> NSRange? { | ||
(self.string as NSString).getNextLine(startingAt: location) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// PixelAligned.swift | ||
// | ||
// | ||
// Created by Khan Winter on 9/10/23. | ||
// | ||
|
||
import Foundation | ||
|
||
public extension NSRect { | ||
/// Creates a rect pixel-aligned on all edges. | ||
var pixelAligned: NSRect { | ||
NSIntegralRectWithOptions(self, .alignAllEdgesNearest) | ||
} | ||
} | ||
|
||
public extension NSPoint { | ||
/// Creates a point that's pixel-aligned. | ||
var pixelAligned: NSPoint { | ||
NSIntegralRectWithOptions(NSRect(x: self.x, y: self.y, width: 0, height: 0), .alignAllEdgesNearest).origin | ||
} | ||
} |
Oops, something went wrong.