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

Refactor the internal data structures holding state like expanded nodes, search results, and validation errors #450

Merged
merged 50 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
bd76f40
chore: refactor DocumentState into a nested structure (WIP)
josdejong Mar 21, 2024
0dfebbb
chore: refactor DocumentState into a nested structure (WIP)
josdejong Mar 27, 2024
3099196
Merge branch 'refs/heads/main' into feat/document-state-refactor
josdejong May 13, 2024
8cb8e6b
chore: use expanded state from `DocumentState2` instead of `expandedM…
josdejong May 13, 2024
825129e
chore: use enforceString from `DocumentState2` instead of `enforceStr…
josdejong May 13, 2024
117a4d7
chore: use visibleSections from `DocumentState2` instead of `visibleS…
josdejong May 13, 2024
3838b71
chore: extract `selection` out of `DocumentState` (WIP)
josdejong May 13, 2024
b5eab71
chore: replace all usages of `DocumentState` with `DocumentState2` (WIP)
josdejong May 14, 2024
aeca9a4
chore: rename `DocumentState2` to `DocumentState` (WIP)
josdejong May 14, 2024
eae7936
chore: create factory functions for DocumentState and create util fun…
josdejong May 14, 2024
b5a7a67
chore: implement `syncDocumentState` (WIP)
josdejong May 14, 2024
6e20748
chore: use `syncDocumentState` and add more unit tests (WIP)
josdejong May 16, 2024
178a019
chore: implement ensureNestedDocumentStateand allow documentState to …
josdejong May 16, 2024
af08ad6
chore: refactor and simplify the implementation and usages of `update…
josdejong May 16, 2024
c2bded4
chore: minor simplification
josdejong May 17, 2024
a041335
Merge branch 'refs/heads/main' into feat/document-state-refactor
josdejong Jun 3, 2024
0f7448e
Merge branch 'main' into feat/document-state-refactor
josdejong Jun 6, 2024
6c587b2
fix: selection not moved to next area inbetween after inserting a new…
josdejong Jun 6, 2024
34c02df
fix: undo/redo not restoring selection correctly
josdejong Jun 6, 2024
6cd564e
fix: restoring selection on undo/redo not working in table mode
josdejong Jun 6, 2024
c4ec91e
fix: issue when pasting objects/arrays in table mode
josdejong Jun 6, 2024
1e5fe3c
fix: enforce string not working in table mode
josdejong Jun 6, 2024
84cbf75
chore: use `setInDocumentState` instead of `setIn`
josdejong Jun 6, 2024
b9b2d4d
Merge branch 'main' into feat/document-state-refactor
josdejong Jun 6, 2024
17420e8
Merge branch 'main' into feat/document-state-refactor
josdejong Jun 6, 2024
801da75
fix: get sortedColumn working again
josdejong Jun 6, 2024
494b238
fix: restore sortedColumn on undo/redo
josdejong Jun 6, 2024
0f3b90e
chore: introduce `DocumentState extends RecursiveState` (WIP)
josdejong Jun 10, 2024
a437451
chore: refactor search results into a nested data structure
josdejong Jun 11, 2024
e0c5747
chore: refactor validationErrors in a recursive data structure
josdejong Jun 11, 2024
309af17
chore: fix linting issues
josdejong Jun 11, 2024
ccd0038
chore: simplify `getProps` and `getItems`
josdejong Jun 11, 2024
f9f6318
chore: create a util function `insertItemsAt`
josdejong Jun 11, 2024
1646ef9
chore: cleanup unused imports
josdejong Jun 11, 2024
ca49cf8
chore: fix linting issue
josdejong Jun 11, 2024
7774e72
chore: make `syncDocumentState` immutable
josdejong Jun 11, 2024
fb1a489
chore: refactor getProps and getItems
josdejong Jun 13, 2024
6714029
chore: pass `pointer` instead of `path` and remove memoization code
josdejong Jun 13, 2024
34f0043
chore: clarify code comment
josdejong Jun 13, 2024
11fa50b
chore: use searchResultByRow in table mode, fix linting issues, cleanup
josdejong Jun 13, 2024
1df142b
chore: minor optimization
josdejong Jun 13, 2024
34dc653
chore: create some helper functions to set/update recursive state
josdejong Jun 13, 2024
2152dfb
chore: rename `RecursiveSearchResult` into `SearchResults`
josdejong Jun 13, 2024
474dcf8
chore: rename `RecursiveValidationErrors` to `ValidationErrors`
josdejong Jun 13, 2024
b8c052a
fix: need to press Enter twice to go to the first next search result …
josdejong Jun 13, 2024
261543c
chore: cleanup some debug statements
josdejong Jun 13, 2024
ef7281e
fix: only enable the "Insert Structure" button in the ContextMenu whe…
josdejong Jun 13, 2024
3a5a144
chore: refactor the previous state used in undo/redo
josdejong Jun 14, 2024
7c8f2ed
chore: update test snapshots
josdejong Jun 14, 2024
f0bd08b
chore: bundle previous state in an object
josdejong Jun 14, 2024
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
4 changes: 2 additions & 2 deletions src/lib/components/__snapshots__/JSONEditor.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ exports[`JSONEditor > render text mode 1`] = `
class="jse-main svelte-ybuk0j"
>
<div
class="jse-text-mode svelte-a0poeb"
class="jse-text-mode svelte-1vwn58i"
>
<div
class="jse-menu svelte-7deygj"
Expand Down Expand Up @@ -701,7 +701,7 @@ exports[`JSONEditor > render text mode 1`] = `
</div>

<div
class="jse-contents svelte-a0poeb"
class="jse-contents svelte-1vwn58i"
>
<div
class="cm-editor ͼ1 ͼ2 ͼ4 ͼt"
Expand Down
26 changes: 14 additions & 12 deletions src/lib/components/controls/SearchBox.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import { DEBOUNCE_DELAY, MAX_SEARCH_RESULTS } from '$lib/constants.js'
import { keyComboFromEvent } from '$lib/utils/keyBindings.js'
import { createDebug } from '$lib/utils/debug.js'
import type { DocumentState, JSONParser, OnPatch, SearchResult } from '$lib/types.js'
import type { DocumentState, JSONParser, OnPatch, SearchResultDetails } from '$lib/types.js'
import {
createSearchAndReplaceOperations,
createSearchAndReplaceAllOperations,
createSearchAndReplaceOperations,
search,
searchNext,
searchPrevious,
search,
updateSearchResult
} from '$lib/logic/search.js'
import type { JSONPath } from 'immutable-json-patch'
Expand All @@ -30,22 +30,22 @@
const debug = createDebug('jsoneditor:SearchBox')

export let json: unknown
export let documentState: DocumentState
export let documentState: DocumentState | undefined
export let parser: JSONParser
export let showSearch: boolean
export let showReplace: boolean
export let readOnly: boolean
export let columns: JSONPath[] | undefined
export let onSearch: (result: SearchResult | undefined) => void
export let onSearch: (result: SearchResultDetails | undefined) => void
export let onFocus: (path: JSONPath) => Promise<void>
export let onPatch: OnPatch
export let onClose: () => void

let text = ''
let previousText = ''
let appliedText = ''
let replaceText = ''
let searching = false
let searchResult: SearchResult | undefined
let searchResult: SearchResultDetails | undefined

$: resultCount = searchResult?.items?.length || 0
$: activeIndex = searchResult?.activeIndex || 0
Expand Down Expand Up @@ -75,10 +75,9 @@
if (combo === 'Enter') {
event.preventDefault()

const pendingChanges = text !== previousText
const pendingChanges = text !== appliedText
if (pendingChanges) {
applyChangedSearchTextDebounced.flush()
previousText = text
} else {
handleNext()
}
Expand Down Expand Up @@ -155,7 +154,8 @@
)

onPatch(operations, (_, patchedState) => ({
state: { ...patchedState, selection: newSelection }
state: patchedState,
selection: newSelection
}))

// immediately trigger updating the search results
Expand All @@ -182,7 +182,8 @@
)

onPatch(operations, (_, patchedState) => ({
state: { ...patchedState, selection: newSelection }
state: patchedState,
selection: newSelection
}))

await handleFocus()
Expand Down Expand Up @@ -249,13 +250,14 @@
return
}

appliedText = text
searching = true

return new Promise<void>((resolve) => {
setTimeout(() => {
// wait until the search icon has been rendered
const newResultItems = search(text, json, { maxResults: MAX_SEARCH_RESULTS, columns })
searchResult = updateSearchResult(json, newResultItems, searchResult)
searchResult = updateSearchResult(newResultItems, searchResult)

searching = false
resolve()
Expand Down
Loading