mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
changed note selection in tree using keyboard - now only sibling nodes are selected
This commit is contained in:
parent
6bbd4c59bc
commit
1e979d71c7
@ -3,8 +3,7 @@ import treeChangesService from "./branches.js";
|
||||
import treeService from "./tree.js";
|
||||
import hoistedNoteService from "./hoisted_note.js";
|
||||
import clipboard from "./clipboard.js";
|
||||
import treeCache from "./tree_cache.js";
|
||||
import searchNoteService from "./search_notes.js";
|
||||
import utils from "./utils.js";
|
||||
import keyboardActionService from "./keyboard_actions.js";
|
||||
|
||||
const fixedKeyBindings = {
|
||||
@ -79,15 +78,17 @@ const templates = {
|
||||
node.setSelected(true);
|
||||
}
|
||||
|
||||
node.navigate($.ui.keyCode.UP, false).then(() => {
|
||||
const currentNode = treeService.getFocusedNode();
|
||||
const prevSibling = node.getPrevSibling();
|
||||
|
||||
if (currentNode.isSelected()) {
|
||||
if (prevSibling) {
|
||||
prevSibling.setActive(true, {noEvents: true});
|
||||
|
||||
if (prevSibling.isSelected()) {
|
||||
node.setSelected(false);
|
||||
}
|
||||
|
||||
currentNode.setSelected(true);
|
||||
});
|
||||
prevSibling.setSelected(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
@ -102,15 +103,17 @@ const templates = {
|
||||
node.setSelected(true);
|
||||
}
|
||||
|
||||
node.navigate($.ui.keyCode.DOWN, false).then(() => {
|
||||
const currentNode = treeService.getFocusedNode();
|
||||
const nextSibling = node.getNextSibling();
|
||||
|
||||
if (currentNode.isSelected()) {
|
||||
if (nextSibling) {
|
||||
nextSibling.setActive(true, {noEvents: true});
|
||||
|
||||
if (nextSibling.isSelected()) {
|
||||
node.setSelected(false);
|
||||
}
|
||||
|
||||
currentNode.setSelected(true);
|
||||
});
|
||||
nextSibling.setSelected(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
@ -163,7 +166,9 @@ async function getKeyboardBindings() {
|
||||
const action = await keyboardActionService.getAction(actionName);
|
||||
|
||||
for (const shortcut of action.effectiveShortcuts || []) {
|
||||
bindings[shortcut] = templates[actionName];
|
||||
const normalizedShortcut = utils.normalizeShortcut(shortcut);
|
||||
|
||||
bindings[normalizedShortcut] = templates[actionName];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,11 +137,7 @@ function bindGlobalShortcut(keyboardShortcut, handler) {
|
||||
|
||||
function bindElShortcut($el, keyboardShortcut, handler) {
|
||||
if (isDesktop()) {
|
||||
keyboardShortcut = keyboardShortcut
|
||||
.toLowerCase()
|
||||
.replace("enter", "return")
|
||||
.replace("ctrl+alt", "alt+ctrl")
|
||||
.replace("meta+alt", "alt+meta"); // alt needs to be first
|
||||
keyboardShortcut = normalizeShortcut(keyboardShortcut);
|
||||
|
||||
$el.bind('keydown', keyboardShortcut, e => {
|
||||
handler(e);
|
||||
@ -152,6 +148,18 @@ function bindElShortcut($el, keyboardShortcut, handler) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize to the form expected by the jquery.hotkeys.js
|
||||
*/
|
||||
function normalizeShortcut(shortcut) {
|
||||
return shortcut
|
||||
.toLowerCase()
|
||||
.replace("enter", "return")
|
||||
.replace("delete", "del")
|
||||
.replace("ctrl+alt", "alt+ctrl")
|
||||
.replace("meta+alt", "alt+meta"); // alt needs to be first;
|
||||
}
|
||||
|
||||
function isMobile() {
|
||||
return window.device === "mobile"
|
||||
// window.device is not available in setup
|
||||
@ -260,5 +268,6 @@ export default {
|
||||
closeActiveDialog,
|
||||
isHtmlEmpty,
|
||||
clearBrowserCache,
|
||||
getUrlForDownload
|
||||
getUrlForDownload,
|
||||
normalizeShortcut
|
||||
};
|
@ -104,7 +104,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
||||
{
|
||||
actionName: "EditNoteTitle",
|
||||
defaultShortcuts: ["Enter"],
|
||||
description: "Edit active note title"
|
||||
description: "Jump from tree to the note detail and edit title"
|
||||
},
|
||||
{
|
||||
actionName: "EditBranchPrefix",
|
||||
@ -117,7 +117,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
||||
},
|
||||
{
|
||||
actionName: "MoveNotesTo",
|
||||
defaultShortcuts: ["CommandOrControl+Shift+C"]
|
||||
defaultShortcuts: ["CommandOrControl+Shift+X"]
|
||||
},
|
||||
|
||||
{
|
||||
|
@ -264,7 +264,6 @@ async function saveLinks(note, content) {
|
||||
if (note.type === 'text') {
|
||||
content = findImageLinks(content, foundLinks);
|
||||
content = findInternalLinks(content, foundLinks);
|
||||
content = findExternalLinks(content, foundLinks);
|
||||
}
|
||||
else if (note.type === 'relation-map') {
|
||||
findRelationMapLinks(content, foundLinks);
|
||||
|
Loading…
x
Reference in New Issue
Block a user