'use strict'

module.exports = (pluginContext) => {
	const shell = pluginContext.shell

	function search (query, res) {
		//format query.
		const query_trim = query.trim()
		if (query_trim.length === 0) {
			return
		}
		//identify file or folder

		//add to res.
		res.add({
			id: query_trim,
			payload: 'open',
			title: query_trim,
			desc: 'Open this File/Folder Path.'
		})
	}

	function execute (id, payload) {
		//open file or folder.
		if (payload !== 'open') {
			return
		}
		shell.openItem(`${id}`)
		//shell.openExternal(`http://www.google.com/search?q=${id}`)
	}

	return { search, execute }
}

@@ -79,16 +79,17 @@
 xt.shell
+;
 %0A%0A%09funct
@@ -138,39 +138,63 @@
 .%0A%09%09
-const
+var
  query_
-trim = query.trim()
+format = %22xxx%22;%0A%09%09//check the length of query
 %0A%09%09i
@@ -202,20 +202,22 @@
  (query_
-trim
+format
 .length 
@@ -230,24 +230,25 @@
  %7B%0A%09%09%09return
+;
 %0A%09%09%7D%0A%09%09//ide
@@ -295,18 +295,23 @@
 res.add(
+%0A%09%09%09
 %7B%0A
+%09
 %09%09%09id: q
@@ -321,16 +321,17 @@
 y_trim,%0A
+%09
 %09%09%09paylo
@@ -345,16 +345,17 @@
 en',%0A%09%09%09
+%09
 title: q
@@ -359,22 +359,25 @@
 : query_
-trim
+format
 ,%0A
+%09
 %09%09%09desc:
@@ -377,17 +377,17 @@
 %09%09desc: 
-'
+%22
 Open thi
@@ -409,14 +409,19 @@
 ath.
-'%0A%09%09%7D)
+%22%0A%09%09%09%7D%0A%09%09);
 %0A%09%7D%0A
@@ -551,71 +551,9 @@
 d%7D%60)
-%0A%09%09//shell.openExternal(%60http://www.google.com/search?q=$%7Bid%7D%60)
+;
 %0A%09%7D%0A
@@ -580,11 +580,12 @@
 xecute %7D
+;
 %0A%7D%0A

add ; and indent.