Skip to content

Commit

Permalink
Merge pull request #242 from KonnorRogers/main
Browse files Browse the repository at this point in the history
main -> latest
  • Loading branch information
KonnorRogers authored Dec 11, 2024
2 parents f45f308 + 45ffbce commit 224214a
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 118 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.14.3

### Patch Changes

- [#240](https://github.com/KonnorRogers/rhino-editor/pull/240) [`9922d58`](https://github.com/KonnorRogers/rhino-editor/commit/9922d584df3fca76960a1a603a169c2c597a0bce) Thanks [@KonnorRogers](https://github.com/KonnorRogers)! - Fix: Remove the cursor placeholder for inserting links due to regressions in mobile browsers.

## 0.14.2

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rhino-editor",
"version": "0.14.2",
"version": "0.14.3",
"description": "A custom element wrapped rich text editor",
"type": "module",
"main": "exports/index.js",
Expand Down
54 changes: 3 additions & 51 deletions src/exports/extensions/selection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Extension } from "@tiptap/core";
import { Plugin, PluginKey, TextSelection } from "@tiptap/pm/state";
import { Plugin, PluginKey } from "@tiptap/pm/state";
import { Decoration, DecorationSet } from "@tiptap/pm/view";
import type { DecorationAttrs } from "@tiptap/pm/view";

Expand All @@ -19,11 +19,6 @@ const selectionPlugin = (options: RhinoSelectionOptions) => {

set = set.remove(set.find());

// Whether selection was explicitly updated by this transaction.
// if (!tr.selectionSet) {
// return set
// }

const { doc, selection } = tr;

let deco: Decoration | null = null;
Expand All @@ -35,62 +30,19 @@ const selectionPlugin = (options: RhinoSelectionOptions) => {
selection.to,
options.HTMLAttributes || {},
);
} else {
// Show a fake cursor.
let widget = document.createElement("placeholder");
// TODO: Make this configurable.
widget.setAttribute("class", "rhino-insertion-placeholder");
widget.setAttribute("readonly", "");
widget.setAttribute("contenteditable", "false");
deco = Decoration.widget(selection.to, widget, {});
}

if (deco) {
set = DecorationSet.create(doc, [deco]);
return DecorationSet.create(doc, [deco]);
}

return set;
return DecorationSet.empty;
},
},
props: {
decorations(state) {
return this.getState(state);
},
handleDOMEvents: {
keydown(view, event) {
if (event.key === "ArrowLeft") {
const { selection } = view.state;
const pos = selection.$from;

// This really bizarre piece of code is to "fix" some weird issue with Decorations and Firefox getting "stuck" on them.
// Basically if youre on a line like this:
// -> Hello
// And your cursor is before the H in Hello, and you hit the "LeftArrow" in Firefox, it will loop to the front. Like so:
// Hi
// |Hello -> "LeftArrow" -> Hello|
// ^ initial cursor position ^ new cursor position
// instead of moving up to the line that says "Hi"
if (selection.empty && pos.parentOffset === 0) {
if (selection.from - 2 <= 0) {
// Call `event.preventDefault()` so that the cursor doesn't jump to front if we're at start of document.
event.preventDefault();
return false;
}

const tr = view.state.tr.setSelection(
TextSelection.create(
view.state.doc,
Math.max(selection.from - 2, 0),
selection.from,
),
);
view.dispatch(tr);
return true;
}
}
return false;
},
},
},
});
};
Expand Down
22 changes: 0 additions & 22 deletions src/exports/styles/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,6 @@ export const cursorStyles = css`
background: var(--rhino-fake-selection-color);
}
/** .fake-cursor-selection is for link "insertions" without selected text. */
:where(.rhino-editor) .rhino-insertion-placeholder {
display: none;
user-select: none;
}
/**
This is used for showing a fake cursor for selections like link insertions
*/
:where(.rhino-editor)[link-dialog-expanded] .rhino-insertion-placeholder {
margin: 0;
padding: 0;
margin-right: -1px;
margin-left: -2px;
border-left-width: 4px;
border-left-style: solid;
border-color: Highlight;
position: relative;
z-index: 1;
display: inline;
}
.ProseMirror-separator {
display: none !important;
}
Expand Down
22 changes: 0 additions & 22 deletions src/exports/styles/rhino-editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,6 @@
background: var(--rhino-fake-selection-color);
}

/** .fake-cursor-selection is for link "insertions" without selected text. */
:where(.rhino-editor) .rhino-insertion-placeholder {
display: none;
user-select: none;
}

/**
This is used for showing a fake cursor for selections like link insertions
*/
:where(.rhino-editor)[link-dialog-expanded] .rhino-insertion-placeholder {
margin: 0;
padding: 0;
margin-right: -1px;
margin-left: -2px;
border-left-width: 4px;
border-left-style: solid;
border-color: Highlight;
position: relative;
z-index: 1;
display: inline;
}

.ProseMirror-separator {
display: none !important;
}
Expand Down
22 changes: 0 additions & 22 deletions src/exports/styles/trix.css
Original file line number Diff line number Diff line change
Expand Up @@ -440,28 +440,6 @@
background: var(--rhino-fake-selection-color);
}

/** .fake-cursor-selection is for link "insertions" without selected text. */
:where(.rhino-editor) .rhino-insertion-placeholder {
display: none;
user-select: none;
}

/**
This is used for showing a fake cursor for selections like link insertions
*/
:where(.rhino-editor)[link-dialog-expanded] .rhino-insertion-placeholder {
margin: 0;
padding: 0;
margin-right: -1px;
margin-left: -2px;
border-left-width: 4px;
border-left-style: solid;
border-color: Highlight;
position: relative;
z-index: 1;
display: inline;
}

.ProseMirror-separator {
display: none !important;
}
Expand Down

0 comments on commit 224214a

Please sign in to comment.