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.
|
||||
|
||||
@@ -63,8 +63,8 @@ li.seqitem { display: block; list-style: none; margin-left: -1.4rem; } .frameedi
|
||||
.mbox { position: absolute; box-sizing: border-box; border: 3px solid #e11; box-shadow: 0 0 0 1px #fff; border-radius: 3px; pointer-events: none; }
|
||||
.mpin { position: absolute; box-sizing: border-box; transform: translate(-50%, -50%); width: 1.6rem; height: 1.6rem; border-radius: 50%; background: #e11; color: #fff; border: 2px solid #fff; font: 700 .85rem/1.2rem system-ui, sans-serif; text-align: center; pointer-events: none; }
|
||||
.annotator { max-width: min(95vw, 70rem); } .annot { display: block; max-width: 100%; max-height: 65vh; margin: .5rem auto; cursor: crosshair; touch-action: none; border: 1px solid var(--line); }
|
||||
.searchbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .75rem 0 1rem; }
|
||||
.searchbox { flex: 1 1 14rem; min-width: 8rem; font: inherit; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: .4rem; background: var(--card); color: var(--fg); }
|
||||
.searchbar { display: flex; flex: 1 1 100%; flex-wrap: wrap; gap: .5rem; align-items: center; }
|
||||
.searchbox { flex: 1 1 14rem; min-width: 8rem; font: inherit; padding: .4rem .6rem; line-height: 1.2; border: 1px solid var(--line); border-radius: .4rem; background: var(--card); color: var(--fg); }
|
||||
.searchnote { min-width: 4.5rem; text-align: right; }
|
||||
mark.hit { background: var(--warn-bg); color: var(--warn-fg); border-radius: .2rem; padding: 0 .1em; }
|
||||
mark.hit.cur { background: var(--accent); color: var(--bg); outline: 2px solid var(--accent); }
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// YYMMDD is the date, X the iteration that day (A first, B second, ...).
|
||||
// Bump with `npm run bump` (see bump-version.js). build.js strips `export`.
|
||||
|
||||
export const APP_VERSION = '261124H';
|
||||
export const APP_VERSION = '261124I';
|
||||
|
||||
const VERSION_RE = /^(\d{6})([A-Z])$/;
|
||||
export const isVersion = (v) => typeof v === 'string' && VERSION_RE.test(v);
|
||||
|
||||
Reference in New Issue
Block a user