-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
36 additions
and
84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ParentBlot } from 'parchment'; | ||
import Module from '../core/module'; | ||
import type Quill from '../core/quill'; | ||
|
||
class UINodeSelection extends Module { | ||
constructor(quill: Quill, options: Record<string, never>) { | ||
super(quill, options); | ||
|
||
document.addEventListener('selectionchange', () => { | ||
const selection = document.getSelection(); | ||
if (!selection) return; | ||
const range = selection.getRangeAt(0); | ||
console.log({ range }); | ||
if (range.collapsed !== true || range.startOffset !== 0) return; | ||
|
||
const line = this.quill.scroll.find(range.startContainer); | ||
if (!(line instanceof ParentBlot) || !line.uiNode) return; | ||
console.log({ line }); | ||
|
||
const newRange = document.createRange(); | ||
newRange.setStartAfter(line.uiNode); | ||
newRange.setEndAfter(line.uiNode); | ||
console.log('newRange', newRange); | ||
selection.removeAllRanges(); | ||
selection.addRange(newRange); | ||
}); | ||
} | ||
} | ||
|
||
export default UINodeSelection; |
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