Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

editor: remove selection persistence

Abdullah Atta1e690664f1a6
diff --git a/packages/editor/src/extensions/selection-persist/index.ts b/packages/editor/src/extensions/selection-persist/index.ts
deleted file mode 100644
index 945eb6862..000000000
--- a/packages/editor/src/extensions/selection-persist/index.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-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.ts
deleted file mode 100644
index b44044941..000000000
--- a/packages/editor/src/extensions/selection-persist/selection-persist.ts
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
-This file is part of the Notesnook project (https://notesnook.com/)
-
-Copyright (C) 2023 Streetwriters (Private) Limited
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program. If not, see <http://www.gnu.org/licenses/>.
-*/
-
-import { Extension } from "@tiptap/core";
-import { Plugin, PluginKey } from "prosemirror-state";
-import { Decoration, DecorationSet } from "prosemirror-view";
-import { SearchStorage } from "../search-replace";
-
-const key = new PluginKey("selection-persist-key");
-export const SelectionPersist = Extension.create({
- name: "selection-persist",
-
- addProseMirrorPlugins() {
- let isFocused = false;
- let isBlurred = false;
- const editor = this.editor;
- return [
- new Plugin({
- key,
- props: {
- decorations(state) {
- return key.getState(state);
- }
- },
- state: {
- init() {
- return DecorationSet.empty;
- },
- apply(tr, _value, oldState) {
- const { isSearching } = (editor.storage.searchreplace ||
- {}) as Partial<SearchStorage>;
- if (isSearching || !editor.isEditable) return DecorationSet.empty;
-
- // 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); font-family: inherit;"
- })
- ]);
- } else if (isFocused) {
- return DecorationSet.empty;
- }
- return DecorationSet.empty;
- }
- }
- })
- ];
- }
-});
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts
index 9537d08df..761da1e3a 100644
--- a/packages/editor/src/index.ts
+++ b/packages/editor/src/index.ts
@@ -64,7 +64,6 @@ import {
usePortalProvider
} from "./extensions/react";
import { SearchReplace } from "./extensions/search-replace";
-import { SelectionPersist } from "./extensions/selection-persist";
import { Table } from "./extensions/table";
import TableCell from "./extensions/table-cell";
import { TaskItemNode } from "./extensions/task-item";
@@ -237,7 +236,6 @@ const useTiptap = (
MathInline,
MathBlock,
KeepInView,
- SelectionPersist,
DateTime.configure({ dateFormat, timeFormat }),
KeyMap,
WebClipNode