Skip to content

Commit

Permalink
fix broken position normalization #427
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Sep 1, 2018
1 parent 4f9b7b5 commit c6765db
Showing 1 changed file with 31 additions and 16 deletions.
47 changes: 31 additions & 16 deletions js/jquery.terminal-src.js
Expand Up @@ -3713,7 +3713,14 @@
// ---------------------------------------------------------------------
// :: apply custom formatters only to text
// ---------------------------------------------------------------------
apply_formatters: function(string, settings) {
apply_formatters: function apply_formatters(string, settings) {
if (string === "") {
if (typeof settings.position === 'number') {
return ["", settings.position];
} else {
return "";
}
}
function test_lengths(formatter, index, ret, string) {
if (!formatter.__no_warn__ &&
$.terminal.length(ret) !== $.terminal.length(string)) {
Expand Down Expand Up @@ -3783,22 +3790,24 @@
if (formatter instanceof Array) {
var options = formatter[2] || {};
result = [string, position < 0 ? 0 : position];
if (options.loop) {
while (result[0].match(formatter[0])) {
if (result[0].match(formatter[0])) {
if (options.loop) {
while (result[0].match(formatter[0])) {
result = $.terminal.tracking_replace(
result[0],
formatter[0],
formatter[1],
result[1]
);
}
} else {
result = $.terminal.tracking_replace(
result[0],
formatter[0],
formatter[1],
result[1]
);
}
} else {
result = $.terminal.tracking_replace(
result[0],
formatter[0],
formatter[1],
result[1]
);
}
if (position < 0) {
return [result[0], -1];
Expand Down Expand Up @@ -3831,20 +3840,26 @@
} else {
position = position_partial[1];
}
// to make sure that output position is not outside the string
if (position >= $.terminal.length(input[0])) {
position = $.terminal.length(string);
}
if (string === input[0]) {
return input;
}
return [string, position];
}
}, input);
if (typeof settings.position === 'number') {
var position = result[1];
position = normalize_position(string, position);
var max = $.terminal.length(result[0]);
if (position > max) {
position = max;
if ($.terminal.length(result[0]) < result[0].length) {
var position = result[1];
position = normalize_position(result[0], position);
var max = $.terminal.length(result[0]);
if (position > max) {
position = max;
}
result[1] = position;
}
result[1] = position;
return result;
} else {
return result[0];
Expand Down

0 comments on commit c6765db

Please sign in to comment.