|
17 | 17 | import "codemirror/addon/edit/closebrackets.js";
|
18 | 18 | import "codemirror/addon/edit/matchtags.js";
|
19 | 19 | import "codemirror/addon/edit/closetag.js";
|
| 20 | + import searchDoc from "/Users/zacharyradford/Desktop/Codesmith/Projects/SvelteStorm/src/SearchProgram.js"; |
| 21 | +
|
| 22 | + const fs = require("fs"); |
| 23 | + const { ipcRenderer } = require("electron"); |
| 24 | + export let word; |
20 | 25 | import {
|
21 | 26 | editorCache,
|
22 | 27 | codeMirrorEditor,
|
23 | 28 | currentTabFilePath,
|
24 | 29 | } from "../Utilities/DirectoryStore.js";
|
25 | 30 |
|
26 |
| - const fs = require("fs"); |
27 |
| - const { ipcRenderer } = require("electron"); |
28 |
| -
|
29 | 31 | export let value;
|
30 | 32 | export let language;
|
31 | 33 | export let filePath;
|
| 34 | + let tipContent = ""; |
32 | 35 | let messageObj;
|
| 36 | + let stillMouse = false; |
| 37 | + let hoverCounter = 0; |
| 38 | + let lastHoverCounter = 0; |
| 39 | + let lastWord; |
| 40 | + let src; |
| 41 | + let showToolTip; |
33 | 42 | let containerElt;
|
| 43 | + let showToolTripTransition = false; |
| 44 | + let noUpdate = false; |
| 45 | +
|
| 46 | + function searchDocumentation(value) { |
| 47 | + if (!value || value === " ") { |
| 48 | + tipContent = " "; |
| 49 | + return false; |
| 50 | + } |
| 51 | + // console.log("first console.log of search", value); |
| 52 | + for (let item in searchDoc) { |
| 53 | + // console.log("here is each item of search", item); |
| 54 | + if (searchDoc[item][0].includes(value)) { |
| 55 | + // console.log("here is each item, value", item, value); |
| 56 | + let result = {}; |
| 57 | + result.tip = searchDoc[item][1][0]; |
| 58 | + result.url = item; |
| 59 | + return result; |
| 60 | + } |
| 61 | + } |
| 62 | + tipContent = " "; |
| 63 | + // console.log(value, "is not in the docs!"); |
| 64 | + return false; |
| 65 | + } |
| 66 | +
|
| 67 | + // let toolTipDiv; |
| 68 | + src = `https://svelte.dev/docs#`; |
| 69 | + function onHover() { |
| 70 | + let word; |
| 71 | + if (stillMouse && searchDocumentation(lastWord) !== false) { |
| 72 | + let searchObj = searchDocumentation(lastWord); |
| 73 | + src = `https://svelte.dev/docs#${searchObj.url}`; |
| 74 | + showToolTip = true; |
| 75 | + tipContent = `${searchObj.tip}`; |
| 76 | + // console.log("this is tipcont", tipContent); |
| 77 | + noUpdate = true; |
| 78 | + lastWord = word; |
| 79 | + } |
| 80 | +
|
| 81 | + var A1 = $codeMirrorEditor.getCursor().line; |
| 82 | + var A2 = $codeMirrorEditor.getCursor().ch; |
| 83 | +
|
| 84 | + var B1 = $codeMirrorEditor.findWordAt({ line: A1, ch: A2 }).anchor.ch; |
| 85 | + var B2 = $codeMirrorEditor.findWordAt({ line: A1, ch: A2 }).head.ch; |
| 86 | +
|
| 87 | + word = $codeMirrorEditor.getRange( |
| 88 | + { line: A1, ch: B1 }, |
| 89 | + { line: A1, ch: B2 } |
| 90 | + ); |
| 91 | +
|
| 92 | + lastWord = word; |
| 93 | + } |
| 94 | +
|
| 95 | + function hoverTest() { |
| 96 | + if (hoverCounter > lastHoverCounter) { |
| 97 | + lastHoverCounter = hoverCounter; |
| 98 | + return; |
| 99 | + } |
| 100 | + stillMouse = true; |
| 101 | + // console.log("hovering", hoverCounter, lastHoverCounter); |
| 102 | + showToolTip = true; |
| 103 | + // console.log("showToolTip is now true TOOLTIP should appear"); |
| 104 | +
|
| 105 | + return; |
| 106 | + } |
| 107 | +
|
| 108 | + setInterval(() => { |
| 109 | + hoverTest(); |
| 110 | + onHover(); |
| 111 | + // console.log("this is the mouse hover console.log ", word, obj); |
| 112 | + }, 700); |
34 | 113 |
|
35 | 114 | onMount(async () => {
|
36 | 115 | $codeMirrorEditor = await CodeMirror.fromTextArea(containerElt, {
|
|
59 | 138 | });
|
60 | 139 |
|
61 | 140 | afterUpdate(async () => {
|
62 |
| - if (codeMirrorEditor) { |
63 |
| - // retrieve code from DirectoryStore.js and store cached code of the tab that the user clicked on |
64 |
| - const cacheCode = $editorCache[$currentTabFilePath]; |
65 |
| -
|
66 |
| - // if file hans't been cached yet |
67 |
| - if (!cacheCode) { |
68 |
| - // cache the file and it's value (value=the raw code that'll appear in the editor) |
69 |
| - $editorCache[currentTabFilePath] = value; |
70 |
| - // set value of current editor to display the current code |
71 |
| - $codeMirrorEditor.setValue(value); |
72 |
| - } else { |
73 |
| - // if file already exists in the cache |
74 |
| - $codeMirrorEditor.setValue(cacheCode); |
75 |
| - $codeMirrorEditor.setOption("mode", language); |
| 141 | + if (!noUpdate && !showToolTripTransition) { |
| 142 | + if (codeMirrorEditor) { |
| 143 | + // retrieve code from DirectoryStore.js and store cached code of the tab that the user clicked on |
| 144 | + const cacheCode = $editorCache[$currentTabFilePath]; |
| 145 | +
|
| 146 | + // if file hans't been cached yet |
| 147 | + if (!cacheCode) { |
| 148 | + // cache the file and it's value (value=the raw code that'll appear in the editor) |
| 149 | + $editorCache[currentTabFilePath] = value; |
| 150 | + // set value of current editor to display the current code |
| 151 | + $codeMirrorEditor.setValue(value); |
| 152 | + } else { |
| 153 | + // if file already exists in the cache |
| 154 | + $codeMirrorEditor.setValue(cacheCode); |
| 155 | + $codeMirrorEditor.setOption("mode", language); |
| 156 | + } |
76 | 157 | }
|
77 | 158 | }
|
| 159 | + noUpdate = false; |
| 160 | + showToolTripTransition = false; |
| 161 | +
|
78 | 162 | console.log("afterUpdate complete");
|
79 | 163 | });
|
80 | 164 |
|
|
84 | 168 | console.log("ipcRenderer complete");
|
85 | 169 | });
|
86 | 170 |
|
| 171 | + function handleMousMove(e) { |
| 172 | + // console.log("here is the event listener in handleMouseMove", e); |
| 173 | + if (hoverCounter - lastHoverCounter > 12) { |
| 174 | + stillMouse = false; |
| 175 | + showToolTripTransition = true; |
| 176 | + showToolTip = false; |
| 177 | + tipContent = " "; |
| 178 | + } |
| 179 | + hoverCounter++; |
| 180 | + // console.log("this is hover counter", hoverCounter); |
| 181 | + } |
| 182 | + function onClick() { |
| 183 | + window.open( |
| 184 | + `${src}`, |
| 185 | + "_blank", |
| 186 | + "top=900,left=200,frame=true,nodeIntegration=no" |
| 187 | + ); |
| 188 | + } |
| 189 | + function onType() { |
| 190 | + // console.log("this is the key down event"); |
| 191 | + hoverCounter += 13; |
| 192 | + } |
87 | 193 | </script>
|
88 | 194 |
|
89 | 195 | <svelte:head />
|
90 |
| -<textarea class={$$props.class} bind:this={containerElt} /> |
| 196 | +<div data-tooltip="tooltip" id="div_span" on:click={onClick}> |
| 197 | + {tipContent} |
| 198 | +</div> |
| 199 | +<div on:mousemove={handleMousMove} on:keydown={onType}> |
| 200 | + <textarea id="textarea" class={$$props.class} bind:this={containerElt} /> |
| 201 | +</div> |
| 202 | + |
| 203 | +<style> |
| 204 | + /* [data-tooltip] */ |
| 205 | + #div_span { |
| 206 | + min-height: 2.7em; |
| 207 | + max-height: 2.7em; |
| 208 | + font-size: 65%; |
| 209 | + position: relative; |
| 210 | + cursor: help; |
| 211 | + background-color: rgba(35, 35, 65, 0.452); |
| 212 | + z-index: 2 !important; |
| 213 | + /* box-shadow: 2px 2px; */ |
| 214 | + } |
| 215 | +
|
| 216 | + #textarea { |
| 217 | + /* width: 100%; */ |
| 218 | + position: relative; |
| 219 | + z-index: 1; |
| 220 | + } |
| 221 | +</style> |
0 commit comments