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 treeService from "./tree.js";
|
||||||
import hoistedNoteService from "./hoisted_note.js";
|
import hoistedNoteService from "./hoisted_note.js";
|
||||||
import clipboard from "./clipboard.js";
|
import clipboard from "./clipboard.js";
|
||||||
import treeCache from "./tree_cache.js";
|
import utils from "./utils.js";
|
||||||
import searchNoteService from "./search_notes.js";
|
|
||||||
import keyboardActionService from "./keyboard_actions.js";
|
import keyboardActionService from "./keyboard_actions.js";
|
||||||
|
|
||||||
const fixedKeyBindings = {
|
const fixedKeyBindings = {
|
||||||
@ -79,15 +78,17 @@ const templates = {
|
|||||||
node.setSelected(true);
|
node.setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.navigate($.ui.keyCode.UP, false).then(() => {
|
const prevSibling = node.getPrevSibling();
|
||||||
const currentNode = treeService.getFocusedNode();
|
|
||||||
|
|
||||||
if (currentNode.isSelected()) {
|
if (prevSibling) {
|
||||||
|
prevSibling.setActive(true, {noEvents: true});
|
||||||
|
|
||||||
|
if (prevSibling.isSelected()) {
|
||||||
node.setSelected(false);
|
node.setSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNode.setSelected(true);
|
prevSibling.setSelected(true);
|
||||||
});
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -102,15 +103,17 @@ const templates = {
|
|||||||
node.setSelected(true);
|
node.setSelected(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
node.navigate($.ui.keyCode.DOWN, false).then(() => {
|
const nextSibling = node.getNextSibling();
|
||||||
const currentNode = treeService.getFocusedNode();
|
|
||||||
|
|
||||||
if (currentNode.isSelected()) {
|
if (nextSibling) {
|
||||||
|
nextSibling.setActive(true, {noEvents: true});
|
||||||
|
|
||||||
|
if (nextSibling.isSelected()) {
|
||||||
node.setSelected(false);
|
node.setSelected(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNode.setSelected(true);
|
nextSibling.setSelected(true);
|
||||||
});
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -163,7 +166,9 @@ async function getKeyboardBindings() {
|
|||||||
const action = await keyboardActionService.getAction(actionName);
|
const action = await keyboardActionService.getAction(actionName);
|
||||||
|
|
||||||
for (const shortcut of action.effectiveShortcuts || []) {
|
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) {
|
function bindElShortcut($el, keyboardShortcut, handler) {
|
||||||
if (isDesktop()) {
|
if (isDesktop()) {
|
||||||
keyboardShortcut = keyboardShortcut
|
keyboardShortcut = normalizeShortcut(keyboardShortcut);
|
||||||
.toLowerCase()
|
|
||||||
.replace("enter", "return")
|
|
||||||
.replace("ctrl+alt", "alt+ctrl")
|
|
||||||
.replace("meta+alt", "alt+meta"); // alt needs to be first
|
|
||||||
|
|
||||||
$el.bind('keydown', keyboardShortcut, e => {
|
$el.bind('keydown', keyboardShortcut, e => {
|
||||||
handler(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() {
|
function isMobile() {
|
||||||
return window.device === "mobile"
|
return window.device === "mobile"
|
||||||
// window.device is not available in setup
|
// window.device is not available in setup
|
||||||
@ -260,5 +268,6 @@ export default {
|
|||||||
closeActiveDialog,
|
closeActiveDialog,
|
||||||
isHtmlEmpty,
|
isHtmlEmpty,
|
||||||
clearBrowserCache,
|
clearBrowserCache,
|
||||||
getUrlForDownload
|
getUrlForDownload,
|
||||||
|
normalizeShortcut
|
||||||
};
|
};
|
@ -104,7 +104,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
|||||||
{
|
{
|
||||||
actionName: "EditNoteTitle",
|
actionName: "EditNoteTitle",
|
||||||
defaultShortcuts: ["Enter"],
|
defaultShortcuts: ["Enter"],
|
||||||
description: "Edit active note title"
|
description: "Jump from tree to the note detail and edit title"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
actionName: "EditBranchPrefix",
|
actionName: "EditBranchPrefix",
|
||||||
@ -117,7 +117,7 @@ const DEFAULT_KEYBOARD_ACTIONS = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
actionName: "MoveNotesTo",
|
actionName: "MoveNotesTo",
|
||||||
defaultShortcuts: ["CommandOrControl+Shift+C"]
|
defaultShortcuts: ["CommandOrControl+Shift+X"]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -264,7 +264,6 @@ async function saveLinks(note, content) {
|
|||||||
if (note.type === 'text') {
|
if (note.type === 'text') {
|
||||||
content = findImageLinks(content, foundLinks);
|
content = findImageLinks(content, foundLinks);
|
||||||
content = findInternalLinks(content, foundLinks);
|
content = findInternalLinks(content, foundLinks);
|
||||||
content = findExternalLinks(content, foundLinks);
|
|
||||||
}
|
}
|
||||||
else if (note.type === 'relation-map') {
|
else if (note.type === 'relation-map') {
|
||||||
findRelationMapLinks(content, foundLinks);
|
findRelationMapLinks(content, foundLinks);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user