June 9, 2017 at 7:40 pm #21927
Yang Yang
Participant
Thank you for the update! Here is my version.
// jumpabove
function isblank(str) {
return /^\s*$/.test(str);
}
var y = document.selection.GetActivePointY(eePosLogical);
if(y > 1) {
if(!isblank(document.GetLine(y))) { // skip nonblank lines
while(y > 1 && !isblank(document.GetLine(y))) y--;
}
else if(!isblank(document.GetLine(y-1))) { // skip nonblank lines
y--;
while(y > 1 && !isblank(document.GetLine(y))) y--;
}
else { // go to start of this block of blanks
while(y > 1 && isblank(document.GetLine(y))) y--;
if(y > 1 || !isblank(document.GetLine(1))) y++;
}
document.selection.SetActivePoint(eePosLogical, 1, y, false);
}
// jumpbelow
function isblank(str) {
return /^\s*$/.test(str);
}
var y = document.selection.GetActivePointY(eePosLogical);
var n = document.GetLines();
if(y < n) {
if(!isblank(document.GetLine(y))) { // skip nonblank lines
while(y < n && !isblank(document.GetLine(y))) y++;
}
else if(!isblank(document.GetLine(y+1))) { // skip nonblank lines
y++;
while(y < n && !isblank(document.GetLine(y))) y++;
}
else { // go to end of this block of blanks
while(y < n && isblank(document.GetLine(y))) y++;
if(y < n || !isblank(document.GetLine(n))) y--;
}
document.selection.SetActivePoint(eePosLogical, 1, y, false);
}