Highlight numbers properly
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
All checks were successful
timw4mail/scroll/pipeline/head This commit looks good
This commit is contained in:
parent
8c54ceb104
commit
01b8535c5e
@ -14,8 +14,9 @@ To simplify running, I'm using [Just](https://github.com/casey/just).
|
|||||||
- Deno: `just deno-run [filename]`
|
- Deno: `just deno-run [filename]`
|
||||||
- TSX: `just tsx-run [filename]`
|
- TSX: `just tsx-run [filename]`
|
||||||
|
|
||||||
Alternatively, there are shell scripts for each runtime in the `bin` folder.
|
Alternatively, there are shell scripts for each runtime in the `bin` folder. So
|
||||||
So you can run the editor by calling `./bin/deno.sh [filename]` without installing Just.
|
you can run the editor by calling `./bin/deno.sh [filename]` without installing
|
||||||
|
Just.
|
||||||
|
|
||||||
Deno is generally used for dev tools, but each runtime should be functionally
|
Deno is generally used for dev tools, but each runtime should be functionally
|
||||||
equivalent running the text editor.
|
equivalent running the text editor.
|
||||||
|
@ -179,6 +179,15 @@ export function isControl(char: string): boolean {
|
|||||||
return isAscii(char) && (code === 0x7f || code < 0x20);
|
return isAscii(char) && (code === 0x7f || code < 0x20);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is the one char string a common separator/operator character
|
||||||
|
*
|
||||||
|
* @param char - a one character string to check
|
||||||
|
*/
|
||||||
|
export function isSeparator(char: string): boolean {
|
||||||
|
return /\s/.test(char) || char === '\0' || ',.()+-/*=~%<>[];'.includes(char);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the key code for a ctrl chord
|
* Get the key code for a ctrl chord
|
||||||
*
|
*
|
||||||
|
@ -1,7 +1,13 @@
|
|||||||
import Ansi from './ansi.ts';
|
import Ansi from './ansi.ts';
|
||||||
|
|
||||||
import { SCROLL_TAB_SIZE } from './config.ts';
|
import { SCROLL_TAB_SIZE } from './config.ts';
|
||||||
import { arrayInsert, isAsciiDigit, strChars, strlen } from './fns.ts';
|
import {
|
||||||
|
arrayInsert,
|
||||||
|
isAsciiDigit,
|
||||||
|
isSeparator,
|
||||||
|
strChars,
|
||||||
|
strlen,
|
||||||
|
} from './fns.ts';
|
||||||
import { highlightToColor, HighlightType } from './highlight.ts';
|
import { highlightToColor, HighlightType } from './highlight.ts';
|
||||||
import Option, { None, Some } from './option.ts';
|
import Option, { None, Some } from './option.ts';
|
||||||
import { SearchDirection } from './types.ts';
|
import { SearchDirection } from './types.ts';
|
||||||
@ -240,8 +246,11 @@ export class Row {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let prevIsSeparator = true;
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (; i < this.rsize;) {
|
for (; i < this.rsize;) {
|
||||||
|
const prevHighlight = (i > 0) ? highlighting[i - 1] : HighlightType.None;
|
||||||
|
|
||||||
// Highlight search matches
|
// Highlight search matches
|
||||||
if (word.isSome()) {
|
if (word.isSome()) {
|
||||||
if (matches.includes(i)) {
|
if (matches.includes(i)) {
|
||||||
@ -254,14 +263,20 @@ export class Row {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight other syntax types
|
// Highlight numbers
|
||||||
const ch = this.rchars[i];
|
const ch = this.rchars[i];
|
||||||
if (isAsciiDigit(ch)) {
|
const isNumeric = isAsciiDigit(ch) &&
|
||||||
|
(prevIsSeparator || prevHighlight === HighlightType.Number);
|
||||||
|
const isDecimalNumeric = ch === '.' &&
|
||||||
|
prevHighlight === HighlightType.Number;
|
||||||
|
const isHexNumeric = ch === 'x' && prevHighlight === HighlightType.Number;
|
||||||
|
if (isNumeric || isDecimalNumeric || isHexNumeric) {
|
||||||
highlighting.push(HighlightType.Number);
|
highlighting.push(HighlightType.Number);
|
||||||
} else {
|
} else {
|
||||||
highlighting.push(HighlightType.None);
|
highlighting.push(HighlightType.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prevIsSeparator = isSeparator(ch);
|
||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user