working going to end of the line and beginning of first
parent
92450e071d
commit
0b9962c6c6
|
@ -1,3 +1,4 @@
|
|||
'use strict';
|
||||
/**
|
||||
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
||||
* This helps other people to understand this code better and helps them to improve it.
|
||||
|
@ -3059,32 +3060,41 @@ function Ace2Inner() {
|
|||
const linesLength = rep.lines.length();
|
||||
|
||||
if (isPageUp) {
|
||||
top.console.log('page up');
|
||||
// go to the top of the visible content
|
||||
rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0] + 1;
|
||||
rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0] + 1;
|
||||
// if the new rep is beyond the viewport, put the caret on the last line
|
||||
if (rep.selStart[0] < 0) {
|
||||
rep.selStart[0] -= visibleLineRange[1] - visibleLineRange[0];
|
||||
rep.selEnd[0] -= visibleLineRange[1] - visibleLineRange[0];
|
||||
// if the new rep is beyond the viewport or first line,
|
||||
if (rep.selStart[0] <= 0) {
|
||||
// put the caret on the first line in the first position
|
||||
rep.selStart = [0, 0];
|
||||
rep.selEnd = [0, 0];
|
||||
}
|
||||
}
|
||||
|
||||
if (isPageDown) {
|
||||
top.console.log('pag edown');
|
||||
// go to the bottom of the last visible content
|
||||
if (rep.selStart[0] === 0) {
|
||||
rep.selStart[0] += visibleLineRange[1] - visibleLineRange[0] - 1;
|
||||
rep.selEnd[0] += visibleLineRange[1] - visibleLineRange[0] - 1;
|
||||
} else {
|
||||
rep.selStart[0] += visibleLineRange[1] - visibleLineRange[0];
|
||||
rep.selEnd[0] += visibleLineRange[1] - visibleLineRange[0];
|
||||
rep.selStart[0] = visibleLineRange[1] - visibleLineRange[0];
|
||||
rep.selEnd[0] = visibleLineRange[1] - visibleLineRange[0];
|
||||
}
|
||||
// if the new rep is beyond the viewport, put the caret on the last line
|
||||
if (rep.selStart[0] > linesLength) {
|
||||
top.console.log('beyond scope');
|
||||
rep.selStart = [linesLength - 1, 0];
|
||||
rep.selEnd = [linesLength - 1, 0];
|
||||
if (rep.selStart[0] === -1) rep.selStart[0] = 0;
|
||||
if (rep.selEnd[0] === -1) rep.selEnd[0] = 0;
|
||||
// if the new rep is beyond the viewport
|
||||
// put the caret on the last line at the end of the line
|
||||
if (rep.selStart[0] >= (linesLength - 1)) {
|
||||
// need current character length of line
|
||||
const line = rep.lines.atIndex(rep.selEnd[0]);
|
||||
let lineLength;
|
||||
if (line) { // need to test if this is needed or not.
|
||||
lineLength = line.width;
|
||||
} else {
|
||||
lineLength = 0;
|
||||
}
|
||||
rep.selStart = [linesLength - 1, lineLength];
|
||||
rep.selEnd = [linesLength - 1, lineLength];
|
||||
}
|
||||
// TODO: Handle if character is X offset from content
|
||||
}
|
||||
|
|
|
@ -365,7 +365,8 @@ Scroll.prototype.getVisibleLineRange = function (rep) {
|
|||
|
||||
Scroll.prototype.getVisibleCharRange = function (rep) {
|
||||
const lineRange = this.getVisibleLineRange(rep);
|
||||
// top.console.log(rep.lines);
|
||||
// top.console.log('char range', 0, rep.lines.offsetOfIndex(lineRange[0]));
|
||||
// top.console.log('char range', 1, rep.lines.offsetOfIndex(lineRange[1]));
|
||||
return [rep.lines.offsetOfIndex(lineRange[0]), rep.lines.offsetOfIndex(lineRange[1])];
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue