Skip to content

Commit

Permalink
Merge pull request #1045 from lblod/fix/placeholders-selectable
Browse files Browse the repository at this point in the history
fix(placeholders): fix placeholders not being selectable
  • Loading branch information
abeforgit authored Nov 23, 2023
2 parents b8d2adb + a4cc408 commit 4226f8d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-rivers-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@lblod/ember-rdfa-editor": patch
---

fix placeholders no longer being selectable with mouse
9 changes: 6 additions & 3 deletions addon/plugins/gap-cursor/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { keydownHandler } from 'prosemirror-keymap';
import { TextSelection, Plugin, Command, EditorState } from 'prosemirror-state';
import { Fragment, Slice } from 'prosemirror-model';
import { Fragment, ResolvedPos, Slice } from 'prosemirror-model';
import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
import { GapCursor } from './gap-cursor';
import { unwrap } from '@lblod/ember-rdfa-editor/utils/_private/option';
Expand Down Expand Up @@ -104,10 +104,13 @@ function mousedown(view: EditorView, event: MouseEvent) {
function resolvePosition(
view: EditorView,
{ pos, inside }: { pos: number; inside: number },
) {
): ResolvedPos {
let result = view.state.doc.resolve(pos);
const parent = inside === -1 ? view.state.doc : view.state.doc.nodeAt(inside);
while (result.parent !== parent) {
if (parent?.isAtom) {
return result;
}
while (result.depth > 0 && result.parent !== parent) {
if (result.index() <= 0) {
result = view.state.doc.resolve(result.before());
} else if (result.index() >= result.parent.childCount - 1) {
Expand Down

0 comments on commit 4226f8d

Please sign in to comment.