Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LayoutTree: use different hideCaret name in table #2775

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/LayoutTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import getStyle from '../selectors/getStyle'
import getThoughtById from '../selectors/getThoughtById'
import isContextViewActive from '../selectors/isContextViewActive'
import nextSibling from '../selectors/nextSibling'
import rootedParentOf from '../selectors/rootedParentOf'
import rootedParentOf, { rootedGrandparentOf } from '../selectors/rootedParentOf'
import simplifyPath from '../selectors/simplifyPath'
import thoughtToPath from '../selectors/thoughtToPath'
import reactMinistore from '../stores/react-ministore'
Expand Down Expand Up @@ -909,7 +909,11 @@ const LayoutTree = () => {
])

const spaceAboveLast = useRef(spaceAboveExtended)

// When the cursor is in a table, all thoughts beneath the table are hidden,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might also be worth mentioning in this comment the reason that this is needed. i.e. Why is col2 a special case for the hideCaret depth?

// so there is no concern about animation name conflicts with subsequent (deeper) thoughts.
const tableDepth = useSelector(state =>
state.cursor && attributeEquals(state, head(rootedGrandparentOf(state, state.cursor)), '=view', 'Table') ? 1 : 0,
)
// The indentDepth multipicand (0.9) causes the horizontal counter-indentation to fall short of the actual indentation, causing a progressive shifting right as the user navigates deeper. This provides an additional cue for the user's depth, which is helpful when autofocus obscures the actual depth, but it must stay small otherwise the thought width becomes too small.
// The indentCursorAncestorTables multipicand (0.5) is smaller, since animating over by the entire width of column 1 is too abrupt.
// (The same multiplicand is applied to the vertical translation that crops hidden thoughts above the cursor.)
Expand Down Expand Up @@ -940,7 +944,7 @@ const LayoutTree = () => {
className={cx(
css({ marginTop: '0.501em' }),
hideCaret({
animation: getHideCaretAnimationName(indentDepth),
animation: getHideCaretAnimationName(indentDepth + tableDepth),
}),
)}
style={{
Expand Down
4 changes: 4 additions & 0 deletions src/selectors/rootedParentOf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ const rootedParentOf = <T extends Context | Path>(state: State, thoughts: T): T
: (state.rootContext as T)
}

/** Calls rootedParentOf twice to get the rooted grandparent of a thought. */
export const rootedGrandparentOf = <T extends Context | Path>(state: State, thoughts: T): T =>
rootedParentOf(state, rootedParentOf(state, thoughts))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a convention on this project, we generally only allow a single, default export that matches the file name. This makes it easier to know where functions live in the project, and is facilitated by the quick file picker that most editors provide. Reducers/Action Creators are an exception, and a few others, but we try to avoid this when possible.

Could move this into its own file in the src/selectors directory?


export default rootedParentOf
Loading