A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
feat: add selection persistance
thecodrr027f095e4983
diff --git a/packages/editor/src/extensions/selection-persist/index.ts b/packages/editor/src/extensions/selection-persist/index.tsnew file mode 100644index 000000000..1bb64b085--- /dev/null+++ b/packages/editor/src/extensions/selection-persist/index.ts@@ -0,0 +1 @@+export * from "./selection-persist";diff --git a/packages/editor/src/extensions/selection-persist/selection-persist.ts b/packages/editor/src/extensions/selection-persist/selection-persist.tsnew file mode 100644index 000000000..408fd498b--- /dev/null+++ b/packages/editor/src/extensions/selection-persist/selection-persist.ts@@ -0,0 +1,57 @@+import { Extension } from "@tiptap/core";+import { Plugin, PluginKey } from "prosemirror-state";+import { Decoration, DecorationSet } from "prosemirror-view";++const key = new PluginKey("selection-persist-key");+export const SelectionPersist = Extension.create({+ name: "selection-persist",++ addProseMirrorPlugins() {+ let isFocused = false;+ let isBlurred = false;+ return [+ new Plugin({+ key,+ props: {+ decorations(state) {+ return key.getState(state);+ },+ },+ state: {+ init() {+ return DecorationSet.empty;+ },+ apply(tr, value, oldState, newState) {+ // isBlurred should remain true until isFocused becomes true+ // isFocused should remain true until isBlurred becomes true++ const _isBlurred = !!tr.getMeta("blur");+ const _isFocused = !!tr.getMeta("focus");++ if (_isFocused) {+ isBlurred = false;+ isFocused = true;+ }++ if (_isBlurred) {+ isBlurred = true;+ isFocused = false;+ }++ const { from, to } = oldState.selection;+ if (isBlurred) {+ return DecorationSet.create(tr.doc, [+ Decoration.inline(from, to, {+ style: `background-color: var(--dimPrimary)`,+ }),+ ]);+ } else if (isFocused) {+ return DecorationSet.empty;+ }+ return DecorationSet.empty;+ },+ },+ }),+ ];+ },+});