Search controls replace the toolbar buttons instead of a permanent row (Refs #27)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
24
src/app.js
24
src/app.js
@@ -13,6 +13,7 @@
|
||||
pwChanged: false, // passphrase changed since the last save
|
||||
tabs: {}, // section id -> id of the sub-tab being shown ('' = General); not saved
|
||||
collapsed: new Set(), // ids of records folded to just their title (view mode only)
|
||||
searchOpen: false, // the search controls are showing in place of the toolbar buttons
|
||||
search: null, // { q, hits: [{sid, eid, n}], i, scroll }: the active search (not saved)
|
||||
searchAll: false, // true only while building the hidden copy the search counts matches in
|
||||
walk: null, // { id, k }: the visual sequence shown as a one-step-at-a-time walkthrough (not saved)
|
||||
@@ -1016,7 +1017,7 @@
|
||||
|
||||
function render() {
|
||||
if (capture && !state.editing) endCapture(); // sharing only lasts while editing
|
||||
if (state.editing) state.search = null; // search is for reading; Edit clears it
|
||||
if (state.editing) { state.search = null; state.searchOpen = false; } // search is for reading; Edit clears it
|
||||
const keepFocus = searchEl && searchEl.contains(document.activeElement) ? document.activeElement : null;
|
||||
root.replaceChildren();
|
||||
if (!state.doc) return root.append(renderStart());
|
||||
@@ -1031,20 +1032,21 @@
|
||||
h('span', { class: 'muted', id: 'version', title: 'Version of this app' }, 'Ver ' + APP_VERSION),
|
||||
h('span', { id: 'dirty', class: 'badge tbd', hidden: !state.dirty }, 'Unsaved changes'),
|
||||
h('span', { id: 'status', class: 'muted', role: 'status' }, state.status)),
|
||||
h('div', { class: 'toolbar' },
|
||||
// While searching, the search controls take the toolbar's place; Cancel brings the buttons back.
|
||||
h('div', { class: 'toolbar' }, state.searchOpen ? searchBarEl() : [
|
||||
btn('Save', () => save(), state.dirty ? 'primary' : ''),
|
||||
state.editing ? btn('Cancel', cancelEdit, '', { title: 'Discard unsaved changes to this section and stop editing' }) : null,
|
||||
btn('Backup copy', () => save({ backup: true })),
|
||||
btn('Change passphrase', changePassphrase),
|
||||
btn('Print…', openPrintDialog),
|
||||
btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : ''))),
|
||||
...(state.editing ? [] : [searchBarEl()]),
|
||||
state.editing ? null : btn('Search', openSearch, '', { id: 'searchopen', title: 'Find a word in the document' }),
|
||||
btn(state.editing ? 'Done editing' : 'Edit', () => { state.editing = !state.editing; render(); }, state.editing ? 'primary' : '')])),
|
||||
...(resetRequested() && !state.resetOffered ? [resetBanner()] : []), // never pass null: append() would print "null"
|
||||
h('div', { class: 'layout' }, renderNav(),
|
||||
h('main', {}, onHeader ? [h('h2', {}, 'Print header'), headerPanel()]
|
||||
: sec ? [h('h2', {}, sec.title), state.editing ? editSection(sec) : viewSection(sec)]
|
||||
: h('p', { class: 'muted' }, 'No sections yet. Choose Edit to add one.'))));
|
||||
if (!state.editing) updateSearchUi();
|
||||
if (state.searchOpen) updateSearchUi();
|
||||
if (keepFocus) keepFocus.focus();
|
||||
highlightSearch();
|
||||
}
|
||||
@@ -1081,6 +1083,12 @@
|
||||
return searchEl;
|
||||
}
|
||||
|
||||
function openSearch() {
|
||||
state.searchOpen = true;
|
||||
render();
|
||||
searchInput.focus();
|
||||
}
|
||||
|
||||
function updateSearchUi() {
|
||||
if (!searchEl) return;
|
||||
const s = state.search;
|
||||
@@ -1130,15 +1138,19 @@
|
||||
|
||||
function runSearch() {
|
||||
const q = searchInput.value.trim();
|
||||
if (!q) return cancelSearch();
|
||||
if (!q) { state.search = null; return render(); }
|
||||
state.search = { q, hits: findAllHits(q), i: -1 };
|
||||
if (state.search.hits.length) stepSearch(1); else render();
|
||||
}
|
||||
|
||||
// Cancel: forget the search and put the toolbar buttons back.
|
||||
function cancelSearch() {
|
||||
searchInput.value = '';
|
||||
state.search = null;
|
||||
state.searchOpen = false;
|
||||
render();
|
||||
const again = document.getElementById('searchopen');
|
||||
if (again) again.focus();
|
||||
}
|
||||
|
||||
// Go to match i: its section, its sub-tab, unfolded, then highlight and scroll to it.
|
||||
|
||||
Reference in New Issue
Block a user