1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

automatic page scrolling, docs updated

This commit is contained in:
j-krl 2020-05-24 02:38:14 -06:00
parent b1d073cdeb
commit c3395133c9
4 changed files with 35 additions and 57 deletions

View File

@ -3,14 +3,12 @@ const open = require('open');
class LinkSelector {
constructor() {
this.noteId_ = null; // the note id
this.scrollTop_ = null; // units from the top of the scroll window
this.renderedText_ = null; // rendered text string with correct newline chars
this.currentLinkIndex_ = null; // currently selected link index from linkStore_
this.linkStore_ = null; // object of all link objects in the text
// this.linkRegex_ = /\\x1B[^\s]+http:\/\/[0-9.]+:[0-9]+\/[0-9]+/g; // link regex being searched for
this.noteId_ = null;
this.scrollTop_ = null; // used so 'o' won't open unhighlighted link after scrolling
this.renderedText_ = null;
this.currentLinkIndex_ = null;
this.linkStore_ = null;
this.linkRegex_ = /http:\/\/[0-9.]+:[0-9]+\/[0-9]+/g;
// const link = /\\x1B\[[0-9]{2}m\\x1B\[[0-9]mhttp:\/\/[0-9.]+:[0-9]+\/[0-9]+\\x1B\[[0-9]{2}m\\x1B\[[0-9]{2}m/g;
}
get link() {
@ -28,10 +26,6 @@ class LinkSelector {
return this.linkStore_[this.currentLinkIndex_].noteY;
}
get scrollTop() {
return this.scrollTop_;
}
findLinks(renderedText) {
const newLinkStore = [];
const lines = renderedText.split('\n');
@ -63,10 +57,12 @@ class LinkSelector {
}
scrollWidget(textWidget) {
if (this.currentLinkIndex_ === null) return;
const noteY = this.linkStore_[this.currentLinkIndex_].noteY;
let viewBoxMin = textWidget.scrollTop_;
let viewBoxMax = viewBoxMin + textWidget.innerHeight;
let viewBoxMin = textWidget.scrollTop_ + 1;
let viewBoxMax = viewBoxMin + textWidget.innerHeight - 2;
if (noteY < viewBoxMin) {
for (; noteY < viewBoxMin; textWidget.pageUp()) {
@ -96,16 +92,11 @@ class LinkSelector {
this.changeLink(textWidget, offset);
return;
}
if (textWidget.scrollTop_ !== this.scrollTop_) {
this.scrollTop_ = textWidget.scrollTop_;
this.changeLink(textWidget, 0);
return;
}
if (textWidget.scrollTop_ !== this.scrollTop_) this.scrollTop_ = textWidget.scrollTop_;
if (!this.linkStore_.length) return null;
let offsetMod = (offset + this.currentLinkIndex_) % this.linkStore_.length;
if (offsetMod < 0) offsetMod = this.linkStore_.length + offsetMod;
if (this.currentLinkIndex_ === null) {
if (offsetMod < 0) this.currentLinkIndex_ = this.linkStore_.length + offsetMod;
@ -114,6 +105,8 @@ class LinkSelector {
return;
}
if (offsetMod < 0) offsetMod = this.linkStore_.length + offsetMod;
this.currentLinkIndex_ = offsetMod;
return;
}

View File

@ -1,24 +1,6 @@
// 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.
// NOTE: tests:
// 1. change contents of a note
// 2. navigate away from note to new note
const { Logger } = require('lib/logger.js');
const Folder = require('lib/models/Folder.js');
@ -485,29 +467,26 @@ class AppGui {
// NOTE: MY SHORTCUTS
} else if (cmd === 'next_link' || cmd === 'previous_link') {
const noteText = this.widget('noteText');
if (noteText.hasFocus) {
// if (noteText.hasFocus) {
noteText.render();
noteText.render();
if (cmd === 'next_link') {
this.linkSelector_.changeLink(noteText, 1);
} else {
this.linkSelector_.changeLink(noteText, -1);
}
if (cmd === 'next_link') this.linkSelector_.changeLink(noteText, 1);
else this.linkSelector_.changeLink(noteText, -1);
this.linkSelector_.scrollWidget(noteText);
this.linkSelector_.scrollWidget(noteText);
const cursorOffsetX = this.widget('mainWindow').width - noteText.innerWidth - 8;
const cursorOffsetY = 1 - noteText.scrollTop_;
const cursorOffsetX = this.widget('mainWindow').width - noteText.innerWidth - 8;
const cursorOffsetY = 1 - noteText.scrollTop_;
if (this.linkSelector_.link) {
this.term_.moveTo(
this.linkSelector_.noteX + cursorOffsetX,
this.linkSelector_.noteY + cursorOffsetY
);
this.term_.term().inverse(this.linkSelector_.link);
}
if (this.linkSelector_.link) {
this.term_.moveTo(
this.linkSelector_.noteX + cursorOffsetX,
this.linkSelector_.noteY + cursorOffsetY
);
setTimeout(() => this.term_.term().inverse(this.linkSelector_.link), 50);
}
// }
} else if (cmd === 'open_link') {
if (this.widget('noteText').hasFocus) {
this.linkSelector_.openLink(this.widget('noteText'));

View File

@ -506,6 +506,9 @@ PAGE_DOWN page_down
ENTER activate
DELETE, BACKSPACE delete
(SPACE) todo toggle $n
n next_link
b previous_link
o open_link
tc toggle_console
tm toggle_metadata
/ search &quot;&quot;

View File

@ -176,6 +176,9 @@ There are two types of shortcuts: those that manipulate the user interface direc
ENTER activate
DELETE, BACKSPACE delete
(SPACE) todo toggle $n
n next_link
b previous_link
o open_link
tc toggle_console
tm toggle_metadata
/ search ""