if (this.fieldType === 'ldr') { return; }
switch (evt.key) {
- case 'Enter': return this.keyEnter(evt);
- case 'Delete': return this.keyDelete(evt);
- case 'ArrowDown': return this.keyArrowDown(evt);
- case 'ArrowUp': return this.keyArrowUp(evt);
+
+ case 'Enter':
+ if (evt.ctrlKey) {
+ // ctrl+enter == insert stub field after focused field
+ // ctrl+shift+enter == insert stub field before focused field
+ this.insertField(evt.shiftKey);
+ }
+
+ evt.preventDefault(); // Bare newlines not allowed.
+ break;
+
+ case 'Delete':
+
+ if (evt.ctrlKey) {
+ // ctrl+delete == delete whole field
+ this.deleteField();
+ evt.preventDefault();
+
+ } else if (evt.shiftKey && this.subfield) {
+ // shift+delete == delete subfield
+
+ this.deleteSubfield();
+ evt.preventDefault();
+ }
+
+ break;
+
+ case 'ArrowDown':
+ if (evt.ctrlKey) {
+ // ctrl+down == copy current field down one
+ this.record.insertFieldsAfter(
+ this.field, this.record.cloneField(this.field));
+ }
+
+ // down == move focus to tag of previous field
+ this.context.focusNextTag(this.field);
+ evt.preventDefault();
+ break;
+
+ case 'ArrowUp':
+ if (evt.ctrlKey) {
+ // ctrl+up == copy current field up one
+ this.record.insertFieldsBefore(
+ this.field, this.record.cloneField(this.field));
+ }
+
+ // up == move focus to tag of previous field
+ this.context.focusPreviousTag(this.field);
+ evt.preventDefault();
+ break;
+
case 'F6':
if (evt.shiftKey) {
}
}
- // ctrl+enter == insert stub field after focused field
- // ctrl+shift+enter == insert stub field before focused field
- keyEnter(evt: KeyboardEvent) {
+ insertField(before: boolean) {
- if (evt.ctrlKey) {
+ const newField = this.record.newField(
+ {tag: '999', subfields: [[' ', '', 0]]});
- const newField = this.record.newField(
- {tag: '999', subfields: [[' ', '', 0]]});
-
- if (evt.shiftKey) {
- this.record.insertFieldsBefore(this.field, newField);
- } else {
- this.record.insertFieldsAfter(this.field, newField);
- }
-
- this.context.requestFieldFocus(
- {fieldId: newField.fieldId, target: 'tag'});
+ if (before) {
+ this.record.insertFieldsBefore(this.field, newField);
+ } else {
+ this.record.insertFieldsAfter(this.field, newField);
}
- evt.preventDefault(); // Bare newlines not allowed.
+ this.context.requestFieldFocus(
+ {fieldId: newField.fieldId, target: 'tag'});
}
- // ctrl+delete == delete whole field
- // shift+delete == delete subfield
- keyDelete(evt: KeyboardEvent) {
-
- if (evt.ctrlKey) {
- const field =
- this.record.getNextField(this.field.fieldId) ||
- this.record.getPreviousField(this.field.fieldId);
-
- if (field) {
- this.context.requestFieldFocus(
- {fieldId: field.fieldId, target: 'tag'});
- }
+ deleteField() {
+ this.context.focusNextTag(this.field) ||
+ this.context.focusPreviousTag(this.field);
- this.record.deleteFields(this.field);
- evt.preventDefault();
-
- } else if (evt.shiftKey && this.subfield) {
-
- // If subfields remain, focus the previous subfield.
- // otherwise focus our tag.
- const sfpos = this.subfield[2] - 1;
-
- this.field.deleteExactSubfields(this.subfield);
-
- const focus: FieldFocusRequest =
- {fieldId: this.field.fieldId, target: 'tag'};
-
- if (sfpos >= 0) {
- focus.target = 'sfv';
- focus.sfOffset = sfpos;
- }
-
- this.context.requestFieldFocus(focus);
-
- evt.preventDefault();
- }
- }
-
- // down == move focus to tag of next field
- // ctrl+down == copy current field down one
- keyArrowDown(evt: KeyboardEvent) {
-
- if (evt.ctrlKey) { // Copy field down
-
- this.record.insertFieldsAfter(
- this.field, this.record.cloneField(this.field));
- }
-
- const field = this.record.getNextField(this.field.fieldId);
- if (field) {
- this.context.requestFieldFocus(
- {fieldId: field.fieldId, target: 'tag'});
- }
-
- evt.preventDefault();
+ this.record.deleteFields(this.field);
}
- // up == move focus to tag of previou field
- // ctrl+up == copy current field up one
- keyArrowUp(evt: KeyboardEvent) {
+ deleteSubfield() {
+ // If subfields remain, focus the previous subfield.
+ // otherwise focus our tag.
+ const sfpos = this.subfield[2] - 1;
- if (evt.ctrlKey) {
+ this.field.deleteExactSubfields(this.subfield);
- this.record.insertFieldsBefore(
- this.field, this.record.cloneField(this.field));
- }
+ const focus: FieldFocusRequest =
+ {fieldId: this.field.fieldId, target: 'tag'};
- const field = this.record.getPreviousField(this.field.fieldId);
- if (field) {
- this.context.requestFieldFocus(
- {fieldId: field.fieldId, target: 'tag'});
+ if (sfpos >= 0) {
+ focus.target = 'sfv';
+ focus.sfOffset = sfpos;
}
- evt.preventDefault();
+ this.context.requestFieldFocus(focus);
}
contextMenuChange(value: string) {