Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
raineorshine committed Jan 3, 2025
1 parent d77905b commit 5c816ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/actions/formatLetterCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ export const formatLetterCaseActionCreator =
const cursor = state.cursor
if (!cursor) return

const originalThoughtValue = pathToThought(state, cursor)?.value
if (originalThoughtValue === undefined) return
const thought = pathToThought(state, cursor)
if (!thought) return state

const updatedThoughtValue = applyLetterCase(command, originalThoughtValue)
const oldValue = thought.value
const newValue = applyLetterCase(command, oldValue)
const simplePath = simplifyPath(state, cursor)

const offset = selection.offsetThought()

dispatch(
editThought({
oldValue: originalThoughtValue,
newValue: updatedThoughtValue,
oldValue,
newValue,
path: simplePath,
force: true,
}),
Expand Down
9 changes: 2 additions & 7 deletions src/hooks/useDragAndDropSubThought.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const drop = (props: DroppableSubthoughts, monitor: DropTargetMonitor) => {
const dropTop = !isExpanded && attributeEquals(state, parentIdTo, '=drop', 'top')

// cannot drop on itself
if (equalPath(thoughtsFrom, props.simplePath)) return
if (!thoughtFrom || !thoughtTo || equalPath(thoughtsFrom, props.simplePath)) return

// cannot move root or em context or target is divider
if (isDivider(thoughtTo?.value) || (isRootOrEM && !sameContext)) {
Expand All @@ -125,11 +125,6 @@ const drop = (props: DroppableSubthoughts, monitor: DropTargetMonitor) => {
return
}

if (!thoughtTo) {
console.warn(`Cannot drop ${thoughtFrom} on itself. Aborting drop.`)
return
}

store.dispatch(
moveThought({
oldPath: thoughtsFrom,
Expand All @@ -139,7 +134,7 @@ const drop = (props: DroppableSubthoughts, monitor: DropTargetMonitor) => {
)

// alert user of move to another context
if (!sameContext && thoughtTo && thoughtFrom) {
if (!sameContext) {
// wait until after MultiGesture has cleared the error so this alert does no get cleared
setTimeout(() => {
const alertFrom = '"' + ellipsize(thoughtFrom.value) + '"'
Expand Down

0 comments on commit 5c816ff

Please sign in to comment.