Allow output highlighting
This commit is contained in:
parent
41c8a5aff0
commit
1d8c7dcb97
@ -66,15 +66,25 @@ class ToHex extends Operation {
|
|||||||
*/
|
*/
|
||||||
highlight(pos, args) {
|
highlight(pos, args) {
|
||||||
const delim = Utils.charRep(args[0] || "Space"),
|
const delim = Utils.charRep(args[0] || "Space"),
|
||||||
len = delim === "\r\n" ? 1 : delim.length;
|
lineSize = args[1],
|
||||||
|
comma = args[2],
|
||||||
|
len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0);
|
||||||
|
|
||||||
pos[0].start = pos[0].start * (2 + len);
|
const countLF = function(p) {
|
||||||
pos[0].end = pos[0].end * (2 + len) - len;
|
// Count the number of LFs from 0 upto p
|
||||||
|
return (p / lineSize | 0) - (p >= lineSize && p % lineSize === 0);
|
||||||
|
};
|
||||||
|
|
||||||
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
|
pos[0].start = pos[0].start * (2 + len) + countLF(pos[0].start);
|
||||||
if (delim === "0x" || delim === "\\x") {
|
pos[0].end = pos[0].end * (2 + len) + countLF(pos[0].end);
|
||||||
pos[0].start += 2;
|
|
||||||
pos[0].end += 2;
|
// if the deliminators are not prepended, trim the trailing deliminator
|
||||||
|
if (!(delim === "0x" || delim === "\\x")) {
|
||||||
|
pos[0].end -= delim.length;
|
||||||
|
}
|
||||||
|
// if there is comma, trim the trailing comma
|
||||||
|
if (comma) {
|
||||||
|
pos[0].end--;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user