Skip to content

Commit

Permalink
The last XPath query is being persisted and can be reused with the ne…
Browse files Browse the repository at this point in the history
…xt query.
  • Loading branch information
rdoubleui committed Dec 16, 2015
1 parent eeb0ed8 commit f3ea33a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/features/xmlXPathEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,17 @@ 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;

let xml = editor.document.getText();
let doc = new dom().parseFromString(xml);

Singleton.setXPathValue(query);

try {
var nodes = xpath.select(query, doc);
}
Expand All @@ -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;
}
}

1 comment on commit f3ea33a

@rdoubleui
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The namespace is what I found on how to handle singletons in TypeScript. Seems somewhat odd. Or should the context be handled during the activation of the extension?

Please sign in to comment.