1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00
This commit is contained in:
j-krl 2020-05-22 05:48:27 -06:00
parent 34e4164e2f
commit 3e2570601f

View File

@ -1,3 +1,25 @@
// NOTE: Notes for myself:
// # tkWidgets methods and getters
// innerheight: how much height the widget takes up
// height: how much height the parent widget takes up
// scrollTop_: index of scrolled lines from the top of the note
// maxScrollTop_: Number of lines I can scroll from the top
// scrollableHeight_: total height of the widget including what is not visible
// scrollUp and scrollDown change the scrollTop_ variable by 1 (up -1, down +1) however, their values can be changed for however much you want to scroll
// x/y will give you relative x/y to widget. absoluteX/absoluteY will give it to the terminal window
// .renderedText includes line breaks but also regex of the links. .text is just plain text with non-wrapped line breaks (\n).
// Blueprint:
// I can get the lines with \n but that doesn't account for line wrap.
// the rendered text link is wrapped: '\x1B[34m\x1B[4m' on either side. except 34m is 24m on the right
// term():
// you can use term.eraseArea() to erase the rectangle you need, then term('<string>') for whatever you want to write
// term('string') writes the string wherever the cursor is.
// Other:
// Use stdout.(_(<command>)) as your console.log. It will show in the app console.
const { Logger } = require('lib/logger.js');
const Folder = require('lib/models/Folder.js');
const BaseItem = require('lib/models/BaseItem.js');
@ -12,6 +34,7 @@ const { reg } = require('lib/registry.js');
const { _ } = require('lib/locale.js');
const Entities = require('html-entities').AllHtmlEntities;
const htmlentities = new Entities().encode;
const open = require('open');
const chalk = require('chalk');
const tk = require('terminal-kit');
@ -455,6 +478,84 @@ class AppGui {
} else {
this.stdout(_('Please select the note or notebook to be deleted first.'));
}
// NOTE: MY SHORTCUTS
} else if (cmd === 'next_link' || cmd === 'previous_link' || cmd === 'open_link') {
const noteText = this.widget('noteText');
const mainWindow = this.widget('mainWindow');
if (noteText.hasFocus) {
noteText.render();
const lines = noteText.renderedText_.split('\n');
// const link = /\\x1B\[[0-9][0-9]m\\x1B\[[0-9]mhttp:\/\/[0-9.]+:[0-9]+\/[0-9]+\\x1B\[[0-9][0-9]m\\x1B\[[0-9][0-9]m/g;
const link = /http:\/\/[0-9.]+:[0-9]+\/[0-9]+/g;
this.term_.moveTo(mainWindow.width - noteText.innerWidth + 1, 1);
this.term_.term().getCursorLocation((error, x, y) => {
if (error) throw new Error('Could not get cursor index');
const innerX = x - mainWindow.width + noteText.innerWidth;
const innerY = y;
const scrollHeight = noteText.scrollableHeight_;
const beginStr = lines[innerY].substr(0, innerX);
const endStr = lines[innerY].substr(innerX, lines[innerY].length - 1);
if (cmd !== 'previous_link') {
const matchesNext = [...beginStr.matchAll(link)];
if (cmd === 'open_link' && matchesNext.length) {
if (matchesNext[0].index === innerX) {
open(matchesNext[0][0]);
return;
}
} else if (cmd === 'next_link' && matchesNext.length > 1) {
this.term_.term().move(matchesNext[1].index - 9, innerY);
this.term_.term().inverse(matchesNext[1]);
return;
}
if (cmd === 'open_link') return;
} else {
const matchesPrev = [...endStr.matchAll(link)];
if (matchesPrev.length) {
this.term_.move(matchesPrev[-1].index - 9, innerY);
this.term_.term().inverse(matchesPrev[-1]);
return;
}
}
let i;
if (cmd === 'next_link') i === scrollHeight ? i = 0 : i = innerY + 1;
else i === 0 ? i = scrollHeight : i = innerY - 1;
for (; i !== innerY; (cmd === 'next_link' ? i++ : i--)) {
if (i === scrollHeight) i = 0;
const matches = [...lines[i].matchAll(link)];
if (cmd === 'next_link') {
if (i === scrollHeight) i = 0;
if (matches.length) {
this.term_.term().move(matches[0].index - 9, i);
this.term_.term().inverse(matches[0][0]);
// this.term_.term().styleReset();
return;
}
} else {
if (i === 0) i = scrollHeight;
if (matches.length) {
this.term_.term().move(matches[matches.length - 1].index - 9, i);
this.term_.term().inverse(matches[matches.length - 1][0]);
// this.term_.term().styleReset();
// noteText.render();
return;
}
}
}
});
}
} else if (cmd === 'toggle_console') {
if (!this.consoleIsShown()) {
this.showConsole();
@ -749,7 +850,6 @@ class AppGui {
// -------------------------------------------------------------------------
// Process shortcut and execute associated command
// -------------------------------------------------------------------------
const shortcutKey = this.currentShortcutKeys_.join('');
const keymapItem = this.keymapItemByKey(shortcutKey);
@ -763,7 +863,6 @@ class AppGui {
this.logger().debug('Shortcut:', shortcutKey, keymapItem);
this.currentShortcutKeys_ = [];
if (keymapItem.type === 'function') {
this.processFunctionCommand(keymapItem.command);
} else if (keymapItem.type === 'prompt') {