Skip to content

Commit

Permalink
addMulticursor: Do not add cursor to multicursor.
Browse files Browse the repository at this point in the history
This allows cursor and multicursor to operate independently, allowing for navigation while thoughts are selecte.

The ignoreCursor was no longer needed and was removed.
  • Loading branch information
raineorshine committed Dec 29, 2024
1 parent 4ac46a3 commit ad49179
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/actions/__tests__/addMulticursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
})
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 3 additions & 1 deletion src/actions/__tests__/subcategorizeMulticursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('subcategorizeMulticursor', () => {
newThought('b'),
newThought('c'),
newThought('d'),
setCursor(['b']),
addMulticursorAtFirstMatch(['b']),
addMulticursorAtFirstMatch(['c']),
subcategorizeMulticursor,
]
Expand Down Expand Up @@ -58,6 +58,7 @@ describe('subcategorizeMulticursor', () => {
- c`,
}),
setCursor(['a', 'b']),
addMulticursorAtFirstMatch(['a', 'b']),
addMulticursorAtFirstMatch(['c']),
subcategorizeMulticursor,
]
Expand Down Expand Up @@ -89,6 +90,7 @@ describe('subcategorizeMulticursor', () => {
- E`,
}),
setCursor(['A', 'C']),
addMulticursorAtFirstMatch(['A', 'C']),
addMulticursorAtFirstMatch(['A', 'D']),
subcategorizeMulticursor,
]
Expand Down
24 changes: 7 additions & 17 deletions src/actions/addMulticursor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 1 addition & 1 deletion src/util/executeCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
}),
)
}
Expand Down

0 comments on commit ad49179

Please sign in to comment.