Skip to content

Commit

Permalink
Scroll hotfix (#2)
Browse files Browse the repository at this point in the history
* Update textarea.js

* Update textarea.js

variables reorder

* Update textarea.js

style
  • Loading branch information
freeart authored Sep 30, 2024
1 parent 954f911 commit 8e3a2a3
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/widgets/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function Textarea(options) {

this.offsetY = 0;
this.offsetX = 0;

this.value = options.value || '';

this.__updateCursor = this._updateCursor.bind(this);
Expand Down Expand Up @@ -120,7 +120,7 @@ Textarea.prototype._updateCursor = function(get) {
// _typeScroll `+ '\n'` thing.
// Maybe not necessary anymore?
if (currentText === '' && this.value[this.value.length - 1] !== '\n') {
currentText = this._clines[currentLine - 1] || '';
//currentText = this._clines[currentLine - 1] || '';
}

line = Math.min(
Expand Down Expand Up @@ -290,7 +290,11 @@ Textarea.prototype._listener = function(ch, key) {
const currentLine = (this._clines.length - 1) + this.offsetY
const copy = this._clines.slice();
const cursorPosition = copy[currentLine].length + this.offsetX;
copy[currentLine] = copy[currentLine].slice(0, cursorPosition - 1) + copy[currentLine].slice(cursorPosition);
if (copy[currentLine] === ''){
copy.splice(currentLine, 1);
}else{
copy[currentLine] = copy[currentLine].slice(0, cursorPosition - 1) + copy[currentLine].slice(cursorPosition);
}
this.value = copy.join('\n');
}
}
Expand Down Expand Up @@ -318,8 +322,8 @@ Textarea.prototype._typeScroll = function() {
// XXX Workaround
var height = this.height - this.iheight;
if (this._clines.length - this.childBase > height) {
const currentLine = (this._clines.length) + this.offsetY
this.scroll(currentLine);
const currentLine = (this._clines.length - 1) + this.offsetY;
this.setScroll(currentLine);
}
};

Expand Down

0 comments on commit 8e3a2a3

Please sign in to comment.