From dae843e086f2935d43f9280f81f4891d674d8cfd Mon Sep 17 00:00:00 2001 From: Takashi Tamura Date: Fri, 12 Oct 2018 00:31:16 +0900 Subject: [PATCH] refactoring --- src/providers/hover.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/providers/hover.ts b/src/providers/hover.ts index 6af45e6bf..5962a5119 100644 --- a/src/providers/hover.ts +++ b/src/providers/hover.ts @@ -175,17 +175,17 @@ export class HoverProvider implements vscode.HoverProvider { let b : RegExpMatchArray | null const current_line = document.lineAt(position.line).text let s = current_line - let base:number = 0 - while (b = s.match(/\$.+?\$|\\\(.+?\\\)/)) { + let base = 0 + while (b = s.match(/\$(?:\\.|[^\\])+?\$|\\\(.+?\\\)/)) { if (b && b.index != null) { - if ( base + b.index <= position.character && position.character <= (base + b.index + b[0].length) ) { - const start = new vscode.Position(position.line, base + b.index) - const end = new vscode.Position(position.line, base + b.index + b[0].length) - const range = new vscode.Range(start, end) + const matchStart = base + b.index + const matchEnd = base + b.index + b[0].length + if ( matchStart <= position.character && position.character <= matchEnd ) { + const range = new vscode.Range(position.line, matchStart, position.line, matchEnd) const ret = this.mathjaxify( this.renderCursor(document, range), '$' ) return [ret, range] }else{ - base += b[0].length + base = matchEnd s = current_line.substring(base) } }else{