From f3ea33a522b45a73219ea01561510fef52a66c20 Mon Sep 17 00:00:00 2001 From: Rajko Winkler Date: Wed, 16 Dec 2015 15:54:48 +0100 Subject: [PATCH] The last XPath query is being persisted and can be reused with the next query. --- src/features/xmlXPathEngine.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/features/xmlXPathEngine.ts b/src/features/xmlXPathEngine.ts index 237ac5f..edaea0a 100644 --- a/src/features/xmlXPathEngine.ts +++ b/src/features/xmlXPathEngine.ts @@ -9,7 +9,8 @@ let resultChannel: OutputChannel = null; export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { window.showInputBox({ placeHolder: 'XPath Query', - prompt: 'Please enter an XPath query to evaluate.' + prompt: 'Please enter an XPath query to evaluate.', + value: Singleton.getXPathValue() }).then((query) => { if (query === undefined) return; @@ -17,6 +18,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { let xml = editor.document.getText(); let doc = new dom().parseFromString(xml); + Singleton.setXPathValue(query); + try { var nodes = xpath.select(query, doc); } @@ -42,4 +45,22 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { resultChannel.show(ViewColumn.Three); }); +} + +namespace Singleton { + + class XPathContext + { + static _lastXPathValue:string = ''; + } + + export function getXPathValue():string + { + return XPathContext._lastXPathValue; + } + + export function setXPathValue(val:string):void + { + XPathContext._lastXPathValue = val; + } } \ No newline at end of file