Fix FSE word wrap bug when no barriers could be located in a > width string
This commit is contained in:
parent
303259841f
commit
a3e257aee3
|
@ -56,9 +56,9 @@ const _ = require('lodash');
|
||||||
// To-Do
|
// To-Do
|
||||||
//
|
//
|
||||||
// * Index pos % for emit scroll events
|
// * Index pos % for emit scroll events
|
||||||
// * Some of this shoudl be async'd where there is lots of processing (e.g. word wrap)
|
// * Some of this should be async'd where there is lots of processing (e.g. word wrap)
|
||||||
// * Fix backspace when col=0 (e.g. bs to prev line)
|
// * Fix backspace when col=0 (e.g. bs to prev line)
|
||||||
// * Add back word delete
|
// * Add word delete (CTRL+????)
|
||||||
// *
|
// *
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,13 +336,10 @@ function MultiLineEditTextView(options) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
this.updateTextWordWrap = function(index) {
|
this.updateTextWordWrap = function(index) {
|
||||||
var nextEolIndex = self.getNextEndOfLineIndex(index);
|
const nextEolIndex = self.getNextEndOfLineIndex(index);
|
||||||
var wrapped = self.wordWrapSingleLine(self.getContiguousText(index, nextEolIndex), 'tabsIntact');
|
const wrapped = self.wordWrapSingleLine(self.getContiguousText(index, nextEolIndex), 'tabsIntact');
|
||||||
var newLines = wrapped.wrapped;
|
const newLines = wrapped.wrapped.map(l => { return { text : l }; } );
|
||||||
|
|
||||||
for(var i = 0; i < newLines.length; ++i) {
|
|
||||||
newLines[i] = { text : newLines[i] };
|
|
||||||
}
|
|
||||||
newLines[newLines.length - 1].eol = true;
|
newLines[newLines.length - 1].eol = true;
|
||||||
|
|
||||||
Array.prototype.splice.apply(
|
Array.prototype.splice.apply(
|
||||||
|
@ -420,44 +417,40 @@ function MultiLineEditTextView(options) {
|
||||||
self.textLines[index].text.slice(col)
|
self.textLines[index].text.slice(col)
|
||||||
].join('');
|
].join('');
|
||||||
|
|
||||||
//self.cursorPos.col++;
|
|
||||||
self.cursorPos.col += c.length;
|
self.cursorPos.col += c.length;
|
||||||
|
|
||||||
var cursorOffset;
|
let cursorOffset;
|
||||||
var absPos;
|
let absPos;
|
||||||
|
|
||||||
if(self.getTextLength(index) > self.dimens.width) {
|
if(self.getTextLength(index) > self.dimens.width) {
|
||||||
//
|
//
|
||||||
// Update word wrapping and |cursorOffset| if the cursor
|
// Update word wrapping and |cursorOffset| if the cursor
|
||||||
// was within the bounds of the wrapped text
|
// was within the bounds of the wrapped text
|
||||||
//
|
//
|
||||||
var lastCol = self.cursorPos.col - c.length;
|
const lastCol = self.cursorPos.col - c.length;
|
||||||
var firstWrapRange = self.updateTextWordWrap(index);
|
const firstWrapRange = self.updateTextWordWrap(index);
|
||||||
if(lastCol >= firstWrapRange.start && lastCol <= firstWrapRange.end) {
|
if(lastCol >= firstWrapRange.start && lastCol <= firstWrapRange.end) {
|
||||||
cursorOffset = self.cursorPos.col - firstWrapRange.start;
|
cursorOffset = self.cursorPos.col - firstWrapRange.start;
|
||||||
|
} else {
|
||||||
|
cursorOffset = firstWrapRange.end;
|
||||||
}
|
}
|
||||||
|
|
||||||
// redraw from current row to end of visible area
|
// redraw from current row to end of visible area
|
||||||
self.redrawRows(self.cursorPos.row, self.dimens.height);
|
self.redrawRows(self.cursorPos.row, self.dimens.height);
|
||||||
|
|
||||||
if(!_.isUndefined(cursorOffset)) {
|
self.cursorBeginOfNextLine();
|
||||||
self.cursorBeginOfNextLine();
|
self.cursorPos.col += cursorOffset;
|
||||||
self.cursorPos.col += cursorOffset;
|
self.client.term.rawWrite(ansi.right(cursorOffset));
|
||||||
self.client.term.rawWrite(ansi.right(cursorOffset));
|
|
||||||
} else {
|
|
||||||
self.moveClientCursorToCursorPos();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
// We must only redraw from col -> end of current visible line
|
// We must only redraw from col -> end of current visible line
|
||||||
//
|
//
|
||||||
absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
|
absPos = self.getAbsolutePosition(self.cursorPos.row, self.cursorPos.col);
|
||||||
|
const renderText = self.getRenderText(index).slice(self.cursorPos.col - c.length);
|
||||||
|
|
||||||
self.client.term.write(
|
self.client.term.write(
|
||||||
ansi.hideCursor() +
|
`${ansi.hideCursor()}${self.getSGRFor('text')}${renderText}${ansi.goto(absPos.row, absPos.col)}${ansi.showCursor()}`,
|
||||||
self.getSGRFor('text') +
|
false // convertLineFeeds
|
||||||
self.getRenderText(index).slice(self.cursorPos.col - c.length) +
|
|
||||||
ansi.goto(absPos.row, absPos.col) +
|
|
||||||
ansi.showCursor(), false
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -495,16 +488,12 @@ function MultiLineEditTextView(options) {
|
||||||
return new Array(self.getRemainingTabWidth(col)).join(expandChar);
|
return new Array(self.getRemainingTabWidth(col)).join(expandChar);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.wordWrapSingleLine = function(s, tabHandling, width) {
|
this.wordWrapSingleLine = function(line, tabHandling = 'expand') {
|
||||||
if(!_.isNumber(width)) {
|
|
||||||
width = self.dimens.width;
|
|
||||||
}
|
|
||||||
|
|
||||||
return wordWrapText(
|
return wordWrapText(
|
||||||
s,
|
line,
|
||||||
{
|
{
|
||||||
width : width,
|
width : self.dimens.width,
|
||||||
tabHandling : tabHandling || 'expand',
|
tabHandling : tabHandling,
|
||||||
tabWidth : self.tabWidth,
|
tabWidth : self.tabWidth,
|
||||||
tabChar : '\t',
|
tabChar : '\t',
|
||||||
}
|
}
|
||||||
|
@ -615,11 +604,7 @@ function MultiLineEditTextView(options) {
|
||||||
|
|
||||||
let wrapped;
|
let wrapped;
|
||||||
text.forEach(line => {
|
text.forEach(line => {
|
||||||
wrapped = self.wordWrapSingleLine(
|
wrapped = self.wordWrapSingleLine(line, 'expand').wrapped;
|
||||||
line, // line to wrap
|
|
||||||
'expand', // tabHandling
|
|
||||||
self.dimens.width
|
|
||||||
).wrapped;
|
|
||||||
|
|
||||||
self.setTextLines(wrapped, index, true); // true=termWithEol
|
self.setTextLines(wrapped, index, true); // true=termWithEol
|
||||||
index += wrapped.length;
|
index += wrapped.length;
|
||||||
|
@ -784,7 +769,7 @@ function MultiLineEditTextView(options) {
|
||||||
var index = self.getTextLinesIndex();
|
var index = self.getTextLinesIndex();
|
||||||
var nextEolIndex = self.getNextEndOfLineIndex(index);
|
var nextEolIndex = self.getNextEndOfLineIndex(index);
|
||||||
var text = self.getContiguousText(index, nextEolIndex);
|
var text = self.getContiguousText(index, nextEolIndex);
|
||||||
var newLines = self.wordWrapSingleLine(text.slice(self.cursorPos.col), 'tabsIntact').wrapped;
|
const newLines = self.wordWrapSingleLine(text.slice(self.cursorPos.col), 'tabsIntact').wrapped;
|
||||||
|
|
||||||
newLines.unshift( { text : text.slice(0, self.cursorPos.col), eol : true } );
|
newLines.unshift( { text : text.slice(0, self.cursorPos.col), eol : true } );
|
||||||
for(var i = 1; i < newLines.length; ++i) {
|
for(var i = 1; i < newLines.length; ++i) {
|
||||||
|
|
Loading…
Reference in New Issue