Use currentField.getSelection instead of window.getSelection
This commit is contained in:
parent
08a6f8f02f
commit
8a525d3643
@ -86,7 +86,7 @@ function onKey(evt: KeyboardEvent): void {
|
|||||||
function onKeyUp(evt: KeyboardEvent): void {
|
function onKeyUp(evt: KeyboardEvent): void {
|
||||||
// Avoid div element on remove
|
// Avoid div element on remove
|
||||||
if (evt.code === "Enter" || evt.code === "Backspace") {
|
if (evt.code === "Enter" || evt.code === "Backspace") {
|
||||||
const anchor = window.getSelection().anchorNode;
|
const anchor = currentField.getSelection().anchorNode;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
nodeIsElement(anchor) &&
|
nodeIsElement(anchor) &&
|
||||||
@ -190,7 +190,7 @@ function insertNewline(): void {
|
|||||||
// differently. so in such cases we note the height has not
|
// differently. so in such cases we note the height has not
|
||||||
// changed and insert an extra newline.
|
// changed and insert an extra newline.
|
||||||
|
|
||||||
const r = window.getSelection().getRangeAt(0);
|
const r = currentField.getSelection().getRangeAt(0);
|
||||||
if (!r.collapsed) {
|
if (!r.collapsed) {
|
||||||
// delete any currently selected text first, making
|
// delete any currently selected text first, making
|
||||||
// sure the delete is undoable
|
// sure the delete is undoable
|
||||||
@ -206,7 +206,7 @@ function insertNewline(): void {
|
|||||||
|
|
||||||
// is the cursor in an environment that respects whitespace?
|
// is the cursor in an environment that respects whitespace?
|
||||||
function inPreEnvironment(): boolean {
|
function inPreEnvironment(): boolean {
|
||||||
const anchor = window.getSelection().anchorNode;
|
const anchor = currentField.getSelection().anchorNode;
|
||||||
const n = nodeIsElement(anchor) ? anchor : anchor.parentElement;
|
const n = nodeIsElement(anchor) ? anchor : anchor.parentElement;
|
||||||
|
|
||||||
return window.getComputedStyle(n).whiteSpace.startsWith("pre");
|
return window.getComputedStyle(n).whiteSpace.startsWith("pre");
|
||||||
@ -310,7 +310,7 @@ function caretToEnd(): void {
|
|||||||
const r = document.createRange();
|
const r = document.createRange();
|
||||||
r.selectNodeContents(currentField);
|
r.selectNodeContents(currentField);
|
||||||
r.collapse(false);
|
r.collapse(false);
|
||||||
const s = document.getSelection();
|
const s = currentField.getSelection();
|
||||||
s.removeAllRanges();
|
s.removeAllRanges();
|
||||||
s.addRange(r);
|
s.addRange(r);
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ function wrapIntoText(front: string, back: string): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wrapInternal(front: string, back: string, plainText: boolean): void {
|
function wrapInternal(front: string, back: string, plainText: boolean): void {
|
||||||
const s = window.getSelection();
|
const s = currentField.getSelection();
|
||||||
let r = s.getRangeAt(0);
|
let r = s.getRangeAt(0);
|
||||||
const content = r.cloneContents();
|
const content = r.cloneContents();
|
||||||
const span = document.createElement("span");
|
const span = document.createElement("span");
|
||||||
|
Loading…
Reference in New Issue
Block a user