Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions app/assets/javascript/lexxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7856,26 +7856,19 @@ class Selection {
this.#containEditorFocus();
}

clear() {
this.current = null;
}

set current(selection) {
if (xr(selection)) {
this.editor.getEditorState().read(() => {
this._current = Lr();
this.#syncSelectedClasses();
});
} else {
this.editor.update(() => {
this.#syncSelectedClasses();
this._current = null;
});
}
this.editor.update(() => {
this.#syncSelectedClasses();
});
}

get current() {
return this._current
get hasNodeSelection() {
let result = false;
this.editor.getEditorState().read(() => {
const selection = Lr();
result = selection !== null && xr(selection);
});
return result
}

get cursorPosition() {
Expand Down Expand Up @@ -8068,18 +8061,18 @@ class Selection {
}

get #currentlySelectedKeys() {
if (this._currentlySelectedKeys) { return this._currentlySelectedKeys }
if (this.currentlySelectedKeys) { return this.currentlySelectedKeys }

this._currentlySelectedKeys = new Set();
this.currentlySelectedKeys = new Set();

const selection = Lr();
if (selection && xr(selection)) {
for (const node of selection.getNodes()) {
this._currentlySelectedKeys.add(node.getKey());
this.currentlySelectedKeys.add(node.getKey());
}
}

return this._currentlySelectedKeys
return this.currentlySelectedKeys
}

#processSelectionChangeCommands() {
Expand Down Expand Up @@ -8209,7 +8202,7 @@ class Selection {
this.#highlightNewItems();

this.previouslySelectedKeys = this.#currentlySelectedKeys;
this._currentlySelectedKeys = null;
this.currentlySelectedKeys = null;
}

#clearPreviouslyHighlightedItems() {
Expand All @@ -8231,31 +8224,31 @@ class Selection {
}

async #selectPreviousNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectPrevious());
} else {
this.#selectInLexical(this.nodeBeforeCursor);
}
}

async #selectNextNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectNext(0, 0));
} else {
this.#selectInLexical(this.nodeAfterCursor);
}
}

async #selectPreviousTopLevelNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectPrevious());
} else {
this.#selectInLexical(this.topLevelNodeBeforeCursor);
}
}

async #selectNextTopLevelNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectNext(0, 0));
} else {
this.#selectInLexical(this.topLevelNodeAfterCursor);
Expand All @@ -8264,10 +8257,9 @@ class Selection {

async #withCurrentNode(fn) {
await nextFrame();
if (this.current) {
if (this.hasNodeSelection) {
this.editor.update(() => {
this.clear();
fn(this.current.getNodes()[0]);
fn(Lr().getNodes()[0]);
this.editor.focus();
});
}
Expand Down Expand Up @@ -9171,8 +9163,8 @@ class Contents {
let focusNode = null;

this.editor.update(() => {
if (xr(this.#selection.current)) {
const nodesToRemove = this.#selection.current.getNodes();
if (this.#selection.hasNodeSelection) {
const nodesToRemove = Lr().getNodes();
if (nodesToRemove.length === 0) return

focusNode = this.#findAdjacentNodeTo(nodesToRemove);
Expand All @@ -9184,7 +9176,6 @@ class Contents {

this.editor.update(() => {
this.#selectAfterDeletion(focusNode);
this.#selection.clear();
this.editor.focus();
});
}
Expand Down
Binary file modified app/assets/javascript/lexxy.js.br
Binary file not shown.
Binary file modified app/assets/javascript/lexxy.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion app/assets/javascript/lexxy.min.js

Large diffs are not rendered by default.

Binary file modified app/assets/javascript/lexxy.min.js.br
Binary file not shown.
Binary file modified app/assets/javascript/lexxy.min.js.gz
Binary file not shown.
5 changes: 2 additions & 3 deletions src/editor/contents.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,8 @@ export default class Contents {
let focusNode = null

this.editor.update(() => {
if ($isNodeSelection(this.#selection.current)) {
const nodesToRemove = this.#selection.current.getNodes()
if (this.#selection.hasNodeSelection) {
const nodesToRemove = $getSelection().getNodes()
if (nodesToRemove.length === 0) return

focusNode = this.#findAdjacentNodeTo(nodesToRemove)
Expand All @@ -291,7 +291,6 @@ export default class Contents {

this.editor.update(() => {
this.#selectAfterDeletion(focusNode)
this.#selection.clear()
this.editor.focus()
})
}
Expand Down
50 changes: 21 additions & 29 deletions src/editor/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,19 @@ export default class Selection {
this.#containEditorFocus()
}

clear() {
this.current = null
}

set current(selection) {
if ($isNodeSelection(selection)) {
this.editor.getEditorState().read(() => {
this._current = $getSelection()
this.#syncSelectedClasses()
})
} else {
this.editor.update(() => {
this.#syncSelectedClasses()
this._current = null
})
}
this.editor.update(() => {
this.#syncSelectedClasses()
})
}

get current() {
return this._current
get hasNodeSelection() {
let result = false
this.editor.getEditorState().read(() => {
const selection = $getSelection()
result = selection !== null && $isNodeSelection(selection)
})
return result
}

get cursorPosition() {
Expand Down Expand Up @@ -236,18 +229,18 @@ export default class Selection {
}

get #currentlySelectedKeys() {
if (this._currentlySelectedKeys) { return this._currentlySelectedKeys }
if (this.currentlySelectedKeys) { return this.currentlySelectedKeys }

this._currentlySelectedKeys = new Set()
this.currentlySelectedKeys = new Set()

const selection = $getSelection()
if (selection && $isNodeSelection(selection)) {
for (const node of selection.getNodes()) {
this._currentlySelectedKeys.add(node.getKey())
this.currentlySelectedKeys.add(node.getKey())
}
}

return this._currentlySelectedKeys
return this.currentlySelectedKeys
}

#processSelectionChangeCommands() {
Expand Down Expand Up @@ -377,7 +370,7 @@ export default class Selection {
this.#highlightNewItems()

this.previouslySelectedKeys = this.#currentlySelectedKeys
this._currentlySelectedKeys = null
this.currentlySelectedKeys = null
}

#clearPreviouslyHighlightedItems() {
Expand All @@ -399,31 +392,31 @@ export default class Selection {
}

async #selectPreviousNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectPrevious())
} else {
this.#selectInLexical(this.nodeBeforeCursor)
}
}

async #selectNextNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectNext(0, 0))
} else {
this.#selectInLexical(this.nodeAfterCursor)
}
}

async #selectPreviousTopLevelNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectPrevious())
} else {
this.#selectInLexical(this.topLevelNodeBeforeCursor)
}
}

async #selectNextTopLevelNode() {
if (this.current) {
if (this.hasNodeSelection) {
await this.#withCurrentNode((currentNode) => currentNode.selectNext(0, 0))
} else {
this.#selectInLexical(this.topLevelNodeAfterCursor)
Expand All @@ -432,10 +425,9 @@ export default class Selection {

async #withCurrentNode(fn) {
await nextFrame()
if (this.current) {
if (this.hasNodeSelection) {
this.editor.update(() => {
this.clear()
fn(this.current.getNodes()[0])
fn($getSelection().getNodes()[0])
this.editor.focus()
})
}
Expand Down