-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Paste, Replace Selection & Dragging Text
- Loading branch information
1 parent
d6a6525
commit 2349077
Showing
10 changed files
with
124 additions
and
78 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,42 @@ | ||
import { Editor } from 'slate'; | ||
import { Selection } from '../model/cursor.ts'; | ||
import { Editor, Range, Point } from 'slate'; | ||
import { Cursor, Selection } from '../model/cursor.ts'; | ||
|
||
export function isSelected(editor: Editor) { | ||
if (!editor.selection) return false; | ||
const { anchor, focus } = editor.selection; | ||
return anchor.offset !== focus.offset; | ||
return anchor.path !== focus.path && anchor.offset !== focus.offset; | ||
} | ||
|
||
// export function getSelection(editor: Editor): Selection { | ||
// if (!editor.selection) return { start: { line: 0, column: 0 }, end: { line: 0, column: 0 } }; | ||
// const { anchor, focus } = editor.selection; | ||
// const { path: startLine, offset: startColumn } = focus; | ||
// const { path: endLine, offset: endColumn } = anchor; | ||
// const start = { line: startLine[0], column: startColumn }; | ||
// const end = { line: endLine[0], column: endColumn }; | ||
// const isRightToLeft = start.line > end.line || (start.line === end.line && start.column > end.column); | ||
// return isRightToLeft ? { start: end, end: start } : { start, end }; | ||
// } | ||
|
||
// does the same as the function above | ||
export function getSelection(editor: Editor): Selection { | ||
if (!editor.selection) return { start: { line: 0, column: 0 }, end: { line: 0, column: 0 } }; | ||
const { anchor, focus } = editor.selection; | ||
const { path: startLine, offset: startColumn } = focus; | ||
const { path: endLine, offset: endColumn } = anchor; | ||
const start = { line: startLine[0], column: startColumn }; | ||
const end = { line: endLine[0], column: endColumn }; | ||
const isRightToLeft = start.line > end.line || (start.line === end.line && start.column > end.column); | ||
return isRightToLeft ? { start: end, end: start } : { start, end }; | ||
const { selection } = editor; | ||
if (!selection) { | ||
return { | ||
start: { line: 0, column: 0 }, | ||
end: { line: 0, column: 0 }, | ||
}; | ||
} | ||
const [start, end] = Range.edges(selection); | ||
return { | ||
start: pointToCursor(start), | ||
end: pointToCursor(end), | ||
}; | ||
} | ||
|
||
function pointToCursor(point: Point): Cursor { | ||
return { | ||
line: point.path[0], | ||
column: point.offset, | ||
}; | ||
} |
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