From cbeb8ea17e27d14ff97f8f616e8c2f2306089892 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 09:01:51 +0100 Subject: [PATCH 1/4] fix setting contentLength --- src/entities/note.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/entities/note.js b/src/entities/note.js index 070d9d4b4..8a7cf219b 100644 --- a/src/entities/note.js +++ b/src/entities/note.js @@ -123,9 +123,11 @@ class Note extends Entity { throw new Error(`Cannot set null content to note ${this.noteId}`); } + content = Buffer.isBuffer(content) ? content : Buffer.from(content); + // force updating note itself so that dateModified is represented correctly even for the content this.forcedChange = true; - this.contentLength = content.length; + this.contentLength = content.byteLength; await this.save(); this.content = content; @@ -134,7 +136,7 @@ class Note extends Entity { noteId: this.noteId, content: content, utcDateModified: dateUtils.utcNowDateTime(), - hash: utils.hash(this.noteId + "|" + content) + hash: utils.hash(this.noteId + "|" + content.toString()) }; if (this.isProtected) { From 1690248e240aa2b61b3e0a223393dec69a812061 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 09:08:33 +0100 Subject: [PATCH 2/4] migration script to fix contentLength = -1 in new notes --- db/migrations/0157__fix_contentLength.sql | 1 + src/services/app_info.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 db/migrations/0157__fix_contentLength.sql diff --git a/db/migrations/0157__fix_contentLength.sql b/db/migrations/0157__fix_contentLength.sql new file mode 100644 index 000000000..63bb6ad35 --- /dev/null +++ b/db/migrations/0157__fix_contentLength.sql @@ -0,0 +1 @@ +UPDATE notes SET contentLength = COALESCE((SELECT COALESCE(LENGTH(content), 0) FROM note_contents WHERE note_contents.noteId = notes.noteId), -1); \ No newline at end of file diff --git a/src/services/app_info.js b/src/services/app_info.js index 587d11e62..0c30da676 100644 --- a/src/services/app_info.js +++ b/src/services/app_info.js @@ -4,7 +4,7 @@ const build = require('./build'); const packageJson = require('../../package'); const {TRILIUM_DATA_DIR} = require('./data_dir'); -const APP_DB_VERSION = 156; +const APP_DB_VERSION = 157; const SYNC_VERSION = 14; const CLIPPER_PROTOCOL_VERSION = "1.0"; From 1876664dfb1ca41ff385d4b4e204bc6739575eb9 Mon Sep 17 00:00:00 2001 From: Heniker Date: Sun, 19 Jan 2020 11:16:36 +0300 Subject: [PATCH 3/4] add hotkey to copy contents with line breaks, fixes #349 (#831) --- src/public/javascripts/services/entrypoints.js | 5 ++++- src/public/javascripts/services/utils.js | 10 +++++++++- src/services/keyboard_actions.js | 4 ++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index f37efbe37..968d2f3ad 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -241,7 +241,7 @@ function registerEntrypoints() { d.showDialog(selectedOrActiveNodes); })); - + keyboardActionService.setGlobalActionHandler("CreateNoteIntoDayNote", async () => { const todayNote = await dateNoteService.getTodayNote(); @@ -288,6 +288,9 @@ function registerEntrypoints() { searchNotesService.searchInSubtree(node.data.noteId); }); + + $('document').on('copy', utils.copySelectionToClipboard) + keyboardActionService.setGlobalActionHandler("CopyWithoutFormating", utils.copySelectionToClipboard) } export default { diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js index c64882fd7..a666b5fcd 100644 --- a/src/public/javascripts/services/utils.js +++ b/src/public/javascripts/services/utils.js @@ -241,6 +241,13 @@ function getUrlForDownload(url) { } } +function copySelectionToClipboard() { + const text = window.getSelection().toString() + if (navigator.clipboard) { + navigator.clipboard.writeText(text) + } +} + export default { reloadApp, parseDate, @@ -273,5 +280,6 @@ export default { isHtmlEmpty, clearBrowserCache, getUrlForDownload, - normalizeShortcut + normalizeShortcut, + copySelectionToClipboard }; \ No newline at end of file diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 3311f91d0..6a4a65f3d 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -306,6 +306,10 @@ const DEFAULT_KEYBOARD_ACTIONS = [ { actionName: "ZoomIn", defaultShortcuts: ["CommandOrControl+="] + }, + { + actionName: "CopyWithoutFormating", + defaultShortcuts: ["Alt+Ctrl+C"] } ]; From ab535bf147edac113299f76f410ff88b2c06735b Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Jan 2020 09:25:35 +0100 Subject: [PATCH 4/4] fixes of the new CopyWithoutFormatting --- src/public/javascripts/services/entrypoints.js | 3 +-- src/public/javascripts/services/utils.js | 4 ++-- src/services/keyboard_actions.js | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 968d2f3ad..a1b2abbad 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -289,8 +289,7 @@ function registerEntrypoints() { searchNotesService.searchInSubtree(node.data.noteId); }); - $('document').on('copy', utils.copySelectionToClipboard) - keyboardActionService.setGlobalActionHandler("CopyWithoutFormating", utils.copySelectionToClipboard) + keyboardActionService.setGlobalActionHandler("CopyWithoutFormatting", utils.copySelectionToClipboard); } export default { diff --git a/src/public/javascripts/services/utils.js b/src/public/javascripts/services/utils.js index a666b5fcd..2c6c0e9f1 100644 --- a/src/public/javascripts/services/utils.js +++ b/src/public/javascripts/services/utils.js @@ -242,9 +242,9 @@ function getUrlForDownload(url) { } function copySelectionToClipboard() { - const text = window.getSelection().toString() + const text = window.getSelection().toString(); if (navigator.clipboard) { - navigator.clipboard.writeText(text) + navigator.clipboard.writeText(text); } } diff --git a/src/services/keyboard_actions.js b/src/services/keyboard_actions.js index 6a4a65f3d..c8b1b7dd5 100644 --- a/src/services/keyboard_actions.js +++ b/src/services/keyboard_actions.js @@ -308,8 +308,8 @@ const DEFAULT_KEYBOARD_ACTIONS = [ defaultShortcuts: ["CommandOrControl+="] }, { - actionName: "CopyWithoutFormating", - defaultShortcuts: ["Alt+Ctrl+C"] + actionName: "CopyWithoutFormatting", + defaultShortcuts: ["CommandOrControl+Alt+C"] } ];