From ad4917901e5aa5ff147a12a0c39f0a98361aa163 Mon Sep 17 00:00:00 2001 From: Raine Revere Date: Sun, 29 Dec 2024 20:07:05 +0000 Subject: [PATCH] addMulticursor: Do not add cursor to multicursor. This allows cursor and multicursor to operate independently, allowing for navigation while thoughts are selecte. The ignoreCursor was no longer needed and was removed. --- src/actions/__tests__/addMulticursor.ts | 4 +--- .../__tests__/subcategorizeMulticursor.ts | 4 +++- src/actions/addMulticursor.ts | 24 ++++++------------- src/util/executeCommand.ts | 2 +- 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/actions/__tests__/addMulticursor.ts b/src/actions/__tests__/addMulticursor.ts index 54e4d780646..2a15d8f646f 100644 --- a/src/actions/__tests__/addMulticursor.ts +++ b/src/actions/__tests__/addMulticursor.ts @@ -19,11 +19,9 @@ describe('addMulticursor', () => { const stateNew = reducerFlow(steps)(initialState()) - const a = contextToPath(stateNew, ['a'])! const b = contextToPath(stateNew, ['b'])! expect(stateNew.multicursors).toEqual({ - [hashPath(a)]: a, [hashPath(b)]: b, }) }) @@ -125,7 +123,7 @@ describe('addMulticursor', () => { newThought('a'), newThought('b'), setCursor(['a']), - (state: State) => addMulticursor(state, { path: contextToPath(state, ['b'])!, ignoreCursor: true }), + (state: State) => addMulticursor(state, { path: contextToPath(state, ['b'])! }), ] const stateNew = reducerFlow(steps)(initialState()) diff --git a/src/actions/__tests__/subcategorizeMulticursor.ts b/src/actions/__tests__/subcategorizeMulticursor.ts index acca0e491b4..339fbe21c5c 100644 --- a/src/actions/__tests__/subcategorizeMulticursor.ts +++ b/src/actions/__tests__/subcategorizeMulticursor.ts @@ -16,7 +16,7 @@ describe('subcategorizeMulticursor', () => { newThought('b'), newThought('c'), newThought('d'), - setCursor(['b']), + addMulticursorAtFirstMatch(['b']), addMulticursorAtFirstMatch(['c']), subcategorizeMulticursor, ] @@ -58,6 +58,7 @@ describe('subcategorizeMulticursor', () => { - c`, }), setCursor(['a', 'b']), + addMulticursorAtFirstMatch(['a', 'b']), addMulticursorAtFirstMatch(['c']), subcategorizeMulticursor, ] @@ -89,6 +90,7 @@ describe('subcategorizeMulticursor', () => { - E`, }), setCursor(['A', 'C']), + addMulticursorAtFirstMatch(['A', 'C']), addMulticursorAtFirstMatch(['A', 'D']), subcategorizeMulticursor, ] diff --git a/src/actions/addMulticursor.ts b/src/actions/addMulticursor.ts index cb1cf335507..e134ef0d868 100644 --- a/src/actions/addMulticursor.ts +++ b/src/actions/addMulticursor.ts @@ -2,26 +2,16 @@ import _ from 'lodash' import Path from '../@types/Path' import State from '../@types/State' import Thunk from '../@types/Thunk' -import { isTouch } from '../browser' import hashPath from '../util/hashPath' -import reducerFlow from '../util/reducerFlow' /** Adds a cursor to the multicursor set. */ -const addMulticursor = (state: State, { path, ignoreCursor }: { path: Path; ignoreCursor?: boolean }): State => { - const isEmpty = !Object.keys(state.multicursors).length - - return reducerFlow([ - state => ({ - ...state, - multicursors: { - ...state.multicursors, - [hashPath(path)]: path, - // on desktop, add the cursor to the multicursor set if it's empty - ...(isEmpty && !ignoreCursor && state.cursor && !isTouch ? { [hashPath(state.cursor)]: state.cursor } : {}), - }, - }), - ])(state) -} +const addMulticursor = (state: State, { path }: { path: Path }): State => ({ + ...state, + multicursors: { + ...state.multicursors, + [hashPath(path)]: path, + }, +}) /** Action-creator for addMulticursor. */ export const addMulticursorActionCreator = diff --git a/src/util/executeCommand.ts b/src/util/executeCommand.ts index ce719b40e66..1ec05fafb30 100644 --- a/src/util/executeCommand.ts +++ b/src/util/executeCommand.ts @@ -191,7 +191,7 @@ export const executeCommandWithMulticursor = (command: Command, { store, type, e paths.map(path => (dispatch, getState) => { const recomputedPath = recomputePath(getState(), head(path)) if (!recomputedPath) return - dispatch(addMulticursor({ path: recomputedPath, ignoreCursor: true })) + dispatch(addMulticursor({ path: recomputedPath })) }), ) }