Skip to content

Commit

Permalink
chore: upgrade playground
Browse files Browse the repository at this point in the history
  • Loading branch information
ikatyang committed Oct 2, 2020
1 parent a9e323c commit 523a6d7
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
/build
/node_modules
/tree-sitter
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[submodule "tree-sitter"]
path = tree-sitter
url = https://github.com/ikatyang/tree-sitter
branch = 0.16.7-custom
[submodule "yaml-test-suite"]
path = yaml-test-suite
url = https://github.com/yaml/yaml-test-suite
Expand Down
24 changes: 16 additions & 8 deletions docs/assets/tree-sitter-playground-0.16.7/playground.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,19 @@ let tree;
return COLORS_BY_INDEX[id % COLORS_BY_INDEX.length];
}

function getLocalStorageItem(key) {
return localStorage.getItem(`${document.title}:${key}`);
}

function setLocalStorageItem(key, value) {
localStorage.setItem(`${document.title}:${key}`, value);
}

function loadState() {
const language = localStorage.getItem("language");
const sourceCode = localStorage.getItem("sourceCode");
const query = localStorage.getItem("query");
const queryEnabled = localStorage.getItem("queryEnabled");
const language = getLocalStorageItem("language");
const sourceCode = getLocalStorageItem("sourceCode");
const query = getLocalStorageItem("query");
const queryEnabled = getLocalStorageItem("queryEnabled");
if (language != null && sourceCode != null && query != null) {
queryInput.value = query;
codeInput.value = sourceCode;
Expand All @@ -434,14 +442,14 @@ let tree;
}

function saveState() {
localStorage.setItem("language", languageSelect.value);
localStorage.setItem("sourceCode", codeEditor.getValue());
setLocalStorageItem("language", languageSelect.value);
setLocalStorageItem("sourceCode", codeEditor.getValue());
saveQueryState();
}

function saveQueryState() {
localStorage.setItem("queryEnabled", queryCheckbox.checked);
localStorage.setItem("query", queryEditor.getValue());
setLocalStorageItem("queryEnabled", queryCheckbox.checked);
setLocalStorageItem("query", queryEditor.getValue());
}

function debounce(func, wait, immediate) {
Expand Down
19 changes: 9 additions & 10 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,17 @@ <h4>Tree</h4>
<script src="assets/tree-sitter-playground-0.16.7/playground.js"></script>

<script>
(codeExample => {
((codeExample, queryExample) => {
const handle = setInterval(() => {
const $codeEditor = document.querySelector('.CodeMirror');
if ($codeEditor) {
const $queryEditor = document.querySelector('#query-container .CodeMirror');
const $queryCheckbox = document.querySelector('#query-checkbox');
if ($codeEditor && $queryEditor) {
$codeEditor.CodeMirror.setValue(codeExample);
if (queryExample) {
$queryEditor.CodeMirror.setValue(queryExample);
if (!$queryCheckbox.checked) $queryCheckbox.click();
}
clearInterval(handle);
}
}, 500);
Expand Down Expand Up @@ -104,8 +110,7 @@ <h4>Tree</h4>
comments: >
Late afternoon is best.
Backup contact is Nancy
Billsmer @ 338-4338.
`);
Billsmer @ 338-4338.`, ``);
</script>

</main>
Expand All @@ -117,9 +122,3 @@ <h4>Tree</h4>
src="https://code.jquery.com/jquery-3.3.1.min.js"
crossorigin="anonymous">
</script>
<script>
let select = document.getElementById('language-select')
select.value = 'yaml'
select.dispatchEvent(new Event('change'))
</script>

2 changes: 1 addition & 1 deletion scripts/setup-tree-sitter.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
git clone https://github.com/ikatyang/tree-sitter --branch 0.16.7-custom --depth 1
git submodule update --init
cd tree-sitter
./script/build-wasm
cargo build --release
1 change: 1 addition & 0 deletions tree-sitter
Submodule tree-sitter added at 1ccb0a

0 comments on commit 523a6d7

Please sign in to comment.