Skip to content

Commit d1e8229

Browse files
stephanielearymmorgannoble
authored andcommitted
LP2084166 MARC edit keyboard fix: up, down, CTRL-D
Fixes broken keyboard shortcut behavior in the MARC rich editor: In tags, indicators, and subfield codes, fixes the up/down arrow keys to move focus to the adjacent row as expected. CTRL-D now prevents browser default behavior (bookmarking the page). Also removes vestigial context menu code, which could cause obsolete contextual menus to appear in some editable fields. Release-note: Fixes up/down arrows, CTRL-D, context menus in MARC editor Signed-off-by: Stephanie Leary <[email protected]> Signed-off-by: Joni Paxton <[email protected]> Signed-off-by: Michele Morgan <[email protected]>
1 parent dbcf07f commit d1e8229

File tree

3 files changed

+23
-95
lines changed

3 files changed

+23
-95
lines changed

Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
[ngClass]="{'auth-invalid': isAuthInvalid()}"
6060
tabindex="{{tabindex}}"
6161
[attr.aria-label]="ariaLabel"
62-
[egContextMenu]="contextMenuEntries()"
6362
(menuItemSelected)="contextMenuChange($event.value)"
6463
(keydown)="inputKeyDown($event)"
6564
(focus)="selectText()"

Open-ILS/src/eg2/src/app/staff/share/marc-edit/editable-content.component.ts

Lines changed: 15 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {filter, debounceTime, distinctUntilChanged, map} from 'rxjs/operators';
55
import {MarcRecord, MarcField, MarcSubfield} from './marcrecord';
66
import {MarcEditContext, FieldFocusRequest, MARC_EDITABLE_FIELD_TYPE,
77
TextUndoRedoAction} from './editor-context';
8-
import {ContextMenuEntry} from '@eg/share/context-menu/context-menu.service';
98
import {StringComponent} from '@eg/share/string/string.component';
109
import {TagTable} from './tagtable.service';
1110
import {ComboboxComponent, ComboboxEntry} from '@eg/share/combobox/combobox.component';
@@ -71,9 +70,6 @@ implements OnInit, AfterViewInit, OnDestroy {
7170
// Cache of fixed field menu options
7271
ffValues: ComboboxEntry[] = [];
7372

74-
// Cache of context menu entries
75-
tagMenuEntries: ContextMenuEntry[] = [];
76-
7773
// Cache of tag combobox entries
7874
tagComboListEntries: ComboboxEntry[] = [];
7975

@@ -365,66 +361,6 @@ implements OnInit, AfterViewInit, OnDestroy {
365361
return null;
366362
}
367363

368-
369-
// These are served dynamically to handle cases where a tag or
370-
// subfield is modified in place.
371-
contextMenuEntries(): ContextMenuEntry[] {
372-
if (this.isLeader) { return; }
373-
374-
switch (this.fieldType) {
375-
case 'tag':
376-
return this.tagContextMenuEntries();
377-
378-
case 'sfc':
379-
return this.tt().getSubfieldCodes(this.field.tag);
380-
381-
case 'sfv':
382-
return this.tt().getSubfieldValues(
383-
this.field.tag, this.subfield[0]);
384-
385-
case 'ind1':
386-
case 'ind2':
387-
return this.tt().getIndicatorValues(
388-
this.field.tag, this.fieldType);
389-
390-
case 'ffld':
391-
return this.tt().getFfValues(this.fixedFieldCode);
392-
}
393-
394-
return null;
395-
}
396-
397-
tagContextMenuEntries(): ContextMenuEntry[] {
398-
399-
// string components may not yet be loaded.
400-
if (this.tagMenuEntries.length > 0 || !this.add006Str) {
401-
return this.tagMenuEntries;
402-
}
403-
404-
this.tagMenuEntries.push(
405-
{label: this.add006Str.text, value: '_add006'},
406-
{label: this.add007Str.text, value: '_add007'},
407-
{label: this.add008Str.text, value: '_add008'}
408-
);
409-
410-
if (!this.field.isCtrlField) {
411-
// Only data field tags get these.
412-
this.tagMenuEntries.push(
413-
{label: this.insertAfterStr.text, value: '_insertAfter'},
414-
{label: this.insertBeforeStr.text, value: '_insertBefore'}
415-
);
416-
}
417-
418-
this.tagMenuEntries.push(
419-
{label: this.deleteFieldStr.text, value: '_deleteField'},
420-
{divider: true}
421-
);
422-
423-
this.tt().getFieldTags().forEach(e => this.tagMenuEntries.push(e));
424-
425-
return this.tagMenuEntries;
426-
}
427-
428364
getContent(): string {
429365

430366
switch (this.fieldType) {
@@ -581,13 +517,15 @@ implements OnInit, AfterViewInit, OnDestroy {
581517
if (evt.ctrlKey) { // redo
582518
this.context.requestRedo();
583519
evt.preventDefault();
520+
evt.stopPropagation();
584521
}
585522
break;
586523

587524
case 'z':
588525
if (evt.ctrlKey) { // undo
589526
this.context.requestUndo();
590527
evt.preventDefault();
528+
evt.stopPropagation();
591529
}
592530
break;
593531

@@ -632,8 +570,10 @@ implements OnInit, AfterViewInit, OnDestroy {
632570
}
633571

634572
// down == move focus to tag of next field
635-
// but not in a combobox or textarea
636-
if (!evt.ctrlKey && !this.suggest && !this.bigText) {
573+
// but not in an open combobox or textarea
574+
if (!evt.ctrlKey && !this.TagComboBox?.instance.isPopupOpen() && !this.bigText) {
575+
evt.preventDefault();
576+
evt.stopPropagation();
637577
// avoid dupe focus requests during copy
638578
this.context.focusNextTag(this.field);
639579
}
@@ -652,8 +592,10 @@ implements OnInit, AfterViewInit, OnDestroy {
652592
}
653593

654594
// up == move focus to tag of previous field
655-
// but not in a combobox or textarea
656-
if (!evt.ctrlKey && !this.suggest && !this.bigText) {
595+
// but not in an open combobox or textarea
596+
if (!evt.ctrlKey && !this.TagComboBox?.instance.isPopupOpen() && !this.bigText) {
597+
evt.preventDefault();
598+
evt.stopPropagation();
657599
// avoid dupe focus requests
658600
this.context.focusPreviousTag(this.field);
659601
}
@@ -675,6 +617,7 @@ implements OnInit, AfterViewInit, OnDestroy {
675617
}
676618

677619
evt.preventDefault(); // Bare newlines not allowed.
620+
evt.stopPropagation();
678621
break;
679622

680623
case 'Delete':
@@ -683,6 +626,7 @@ implements OnInit, AfterViewInit, OnDestroy {
683626
// ctrl+delete == delete whole field
684627
this.context.deleteField(this.field);
685628
evt.preventDefault();
629+
evt.stopPropagation();
686630

687631
} else if (evt.shiftKey) {
688632

@@ -694,6 +638,7 @@ implements OnInit, AfterViewInit, OnDestroy {
694638
// prevent any shift-delete from bubbling up becuase
695639
// unexpected stuff will be deleted.
696640
evt.preventDefault();
641+
evt.stopPropagation();
697642
}
698643

699644
break;
@@ -705,6 +650,7 @@ implements OnInit, AfterViewInit, OnDestroy {
705650
const pos = this.subfield ? this.subfield[2] + 1 : 0;
706651
this.context.insertStubSubfield(this.field, pos);
707652
evt.preventDefault();
653+
evt.stopPropagation();
708654
}
709655
break;
710656
}
@@ -713,7 +659,7 @@ implements OnInit, AfterViewInit, OnDestroy {
713659

714660
// if the user has added the max number of characters for the field, advance focus to the next input
715661
// NOT USED
716-
// TODO: to use, add (input)="inputEvent(inputSize(), $event)" to eg-combobox
662+
// TODO: to use, add (input)="inputEvent(inputSize (), $event)" to eg-combobox
717663
skipToNext(max: number, $event?: InputEvent) {
718664
if ($event.data.length === max) {
719665
switch (this.fieldType) {
@@ -776,25 +722,6 @@ implements OnInit, AfterViewInit, OnDestroy {
776722
this.context.requestFieldFocus(focus);
777723
}
778724

779-
contextMenuChange(value: string) {
780-
781-
switch (value) {
782-
case '_add006': return this.context.add00X('006');
783-
case '_add007': return this.context.add00X('007');
784-
case '_add008': return this.context.insertReplace008();
785-
case '_insertBefore':
786-
return this.context.insertStubField(this.field, true);
787-
case '_insertAfter':
788-
return this.context.insertStubField(this.field);
789-
case '_deleteField': return this.context.deleteField(this.field);
790-
}
791-
792-
this.setContent(value, true);
793-
794-
// Context menus can steal focus.
795-
this.context.requestFieldFocus(this.context.lastFocused);
796-
}
797-
798725
isAuthInvalid(): boolean {
799726
return (
800727
this.fieldType === 'sfv' &&

Open-ILS/src/eg2/src/app/staff/share/marc-edit/rich-editor.component.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,15 @@ export class MarcRichEditorComponent implements OnInit {
221221
if (evt.ctrlKey) { // redo
222222
this.context.requestRedo();
223223
evt.preventDefault();
224+
evt.stopPropagation();
224225
}
225226
break;
226227

227228
case 'z':
228229
if (evt.ctrlKey) { // undo
229230
this.context.requestUndo();
230231
evt.preventDefault();
232+
evt.stopPropagation();
231233
}
232234
break;
233235

@@ -268,8 +270,7 @@ export class MarcRichEditorComponent implements OnInit {
268270

269271
// down == move focus to tag of next field
270272
// but not in a combobox or textarea
271-
if (!evt.ctrlKey) {
272-
// avoid dupe focus requests during copy
273+
if (!evt.ctrlKey && !(subfield && this.context.subfieldHasFocus(field, subfield))) {
273274
this.context.focusNextTag(field);
274275
}
275276
break;
@@ -283,9 +284,8 @@ export class MarcRichEditorComponent implements OnInit {
283284
}
284285

285286
// up == move focus to tag of previous field
286-
// but not in a combobox or textarea
287-
if (!evt.ctrlKey) {
288-
// avoid dupe focus requests
287+
// but not in a subfield
288+
if (!evt.ctrlKey && !(subfield && this.context.subfieldHasFocus(field, subfield))) {
289289
this.context.focusPreviousTag(field);
290290
}
291291
break;
@@ -308,7 +308,7 @@ export class MarcRichEditorComponent implements OnInit {
308308
// ctrl+delete == delete whole field
309309
this.context.deleteField(field);
310310
evt.preventDefault();
311-
311+
evt.stopPropagation();
312312
} else if (evt.shiftKey) {
313313

314314
if (subfield) {
@@ -319,6 +319,7 @@ export class MarcRichEditorComponent implements OnInit {
319319
// prevent any shift-delete from bubbling up becuase
320320
// unexpected stuff will be deleted.
321321
evt.preventDefault();
322+
evt.stopPropagation();
322323
}
323324

324325
break;
@@ -330,6 +331,7 @@ export class MarcRichEditorComponent implements OnInit {
330331
const pos = subfield ? subfield[2] + 1 : 0;
331332
this.context.insertStubSubfield(field, pos);
332333
evt.preventDefault();
334+
evt.stopPropagation();
333335
}
334336
break;
335337
}

0 commit comments

Comments
 (0)