attr detail automatically focuses the name input and allows saving with ctrl+enter.

This commit is contained in:
zadam 2020-09-01 22:47:36 +02:00
parent bf548f9d38
commit 0aef99b98e
6 changed files with 32 additions and 19 deletions

View File

@ -7,6 +7,7 @@ import noteAutocompleteService from "../services/note_autocomplete.js";
import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js'; import promotedAttributeDefinitionParser from '../services/promoted_attribute_definition_parser.js';
import TabAwareWidget from "./tab_aware_widget.js"; import TabAwareWidget from "./tab_aware_widget.js";
import SpacedUpdate from "../services/spaced_update.js"; import SpacedUpdate from "../services/spaced_update.js";
import utils from "../services/utils.js";
const TPL = ` const TPL = `
<div class="attr-detail"> <div class="attr-detail">
@ -145,7 +146,7 @@ const TPL = `
<div class="attr-save-delete-button-container"> <div class="attr-save-delete-button-container">
<button class="btn btn-primary btn-sm attr-save-changes-and-close-button" <button class="btn btn-primary btn-sm attr-save-changes-and-close-button"
style="flex-grow: 1; margin-right: 20px"> style="flex-grow: 1; margin-right: 20px">
Save & close</button> Save & close <kbd>Ctrl+Enter</kbd></button>
<button class="btn btn-secondary btn-sm attr-delete-button"> <button class="btn btn-secondary btn-sm attr-delete-button">
Delete</button> Delete</button>
@ -221,6 +222,9 @@ export default class AttributeDetailWidget extends TabAwareWidget {
this.relatedNotesSpacedUpdate = new SpacedUpdate(async () => this.updateRelatedNotes(), 1000); this.relatedNotesSpacedUpdate = new SpacedUpdate(async () => this.updateRelatedNotes(), 1000);
this.$widget = $(TPL); this.$widget = $(TPL);
utils.bindElShortcut(this.$widget, 'ctrl+return', () => this.saveAndClose());
this.contentSized(); this.contentSized();
this.$title = this.$widget.find('.attr-detail-title'); this.$title = this.$widget.find('.attr-detail-title');
@ -291,11 +295,7 @@ export default class AttributeDetailWidget extends TabAwareWidget {
this.$attrSaveDeleteButtonContainer = this.$widget.find('.attr-save-delete-button-container'); this.$attrSaveDeleteButtonContainer = this.$widget.find('.attr-save-delete-button-container');
this.$saveAndCloseButton = this.$widget.find('.attr-save-changes-and-close-button'); this.$saveAndCloseButton = this.$widget.find('.attr-save-changes-and-close-button');
this.$saveAndCloseButton.on('click', async () => { this.$saveAndCloseButton.on('click', () => this.saveAndClose());
await this.triggerCommand('saveAttributes');
this.hide();
});
this.$deleteButton = this.$widget.find('.attr-delete-button'); this.$deleteButton = this.$widget.find('.attr-delete-button');
this.$deleteButton.on('click', async () => { this.$deleteButton.on('click', async () => {
@ -326,6 +326,12 @@ export default class AttributeDetailWidget extends TabAwareWidget {
}); });
} }
async saveAndClose() {
await this.triggerCommand('saveAttributes');
this.hide();
}
userEditedAttribute() { userEditedAttribute() {
this.updateAttributeInEditor(); this.updateAttributeInEditor();
this.updateHelp(); this.updateHelp();
@ -350,7 +356,7 @@ export default class AttributeDetailWidget extends TabAwareWidget {
} }
} }
async showAttributeDetail({allAttributes, attribute, isOwned, x, y}) { async showAttributeDetail({allAttributes, attribute, isOwned, x, y, focus}) {
if (!attribute) { if (!attribute) {
this.hide(); this.hide();
@ -474,6 +480,10 @@ export default class AttributeDetailWidget extends TabAwareWidget {
this.$widget.outerHeight() + y > $(window).height() - 50 this.$widget.outerHeight() + y > $(window).height() - 50
? $(window).height() - y - 50 ? $(window).height() - y - 50
: 10000); : 10000);
if (focus === 'name') {
this.$inputName.focus().select();
}
} }
async updateRelatedNotes() { async updateRelatedNotes() {

View File

@ -55,6 +55,7 @@ const TPL = `
.attribute-errors { .attribute-errors {
color: red; color: red;
padding: 5px 50px 0px 5px; /* large right padding to avoid buttons */
} }
</style> </style>
@ -196,11 +197,7 @@ export default class AttributeEditorWidget extends TabAwareWidget {
this.initialized = this.initEditor(); this.initialized = this.initEditor();
this.$editor.on('keydown', async e => { this.$editor.on('keydown', async e => {
const keycode = (e.keyCode ? e.keyCode : e.which); if (e.which === 13) {
if (keycode === 13) {
this.triggerCommand('focusOnDetail', {tabId: this.tabContext.tabId});
await this.save(); await this.save();
} }
@ -283,7 +280,8 @@ export default class AttributeEditorWidget extends TabAwareWidget {
attribute: attrs[attrs.length - 1], attribute: attrs[attrs.length - 1],
isOwned: true, isOwned: true,
x: (rect.left + rect.right) / 2, x: (rect.left + rect.right) / 2,
y: rect.bottom y: rect.bottom,
focus: 'name'
}); });
}, 100); }, 100);
} }
@ -402,7 +400,7 @@ export default class AttributeEditorWidget extends TabAwareWidget {
html: true, html: true,
title: HELP_TEXT, title: HELP_TEXT,
placement: 'bottom', placement: 'bottom',
offset: "0,20" offset: "0,30"
}); });
} }

View File

@ -829,3 +829,8 @@ body {
ul.fancytree-container li { ul.fancytree-container li {
contain: layout paint; contain: layout paint;
} }
/** ckeditor's autocomplete */
.ck.ck-balloon-panel {
z-index: 10001;
}

View File

@ -78,7 +78,7 @@ function findNotesWithQuery(query, parsingContext) {
} }
return findNotesWithExpression(expression); return findNotesWithExpression(expression);
}); }, 20);
} }
/** /**
@ -180,7 +180,7 @@ function highlightSearchResults(searchResults, highlightedTokens) {
function formatAttribute(attr) { function formatAttribute(attr) {
if (attr.type === 'relation') { if (attr.type === 'relation') {
return '@' + utils.escapeHtml(attr.name) + "=…"; return '~' + utils.escapeHtml(attr.name) + "=…";
} }
else if (attr.type === 'label') { else if (attr.type === 'label') {
let label = '#' + utils.escapeHtml(attr.name); let label = '#' + utils.escapeHtml(attr.name);

View File

@ -16,8 +16,8 @@
</div> </div>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="show-in-full-text-button" class="btn btn-sm">Search in full text <kbd>ctrl+enter</kbd></button> <button id="show-in-full-text-button" class="btn btn-sm">Search in full text <kbd>Ctrl+Enter</kbd></button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -13,7 +13,7 @@
<textarea id="markdown-import-textarea" style="height: 340px; width: 100%"></textarea> <textarea id="markdown-import-textarea" style="height: 340px; width: 100%"></textarea>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button id="markdown-import-button" class="btn btn-primary">Import <kbd>ctrl+enter</kbd></button> <button id="markdown-import-button" class="btn btn-primary">Import <kbd>Ctrl+Enter</kbd></button>
</div> </div>
</div> </div>
</div> </div>