-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SQUASHED: AUTO-COMMIT-demos-tree-sitter-codemirror.md,AUTO-COMMIT-src-components-widgets-lively-code-mirror.html,AUTO-COMMIT-src-components-widgets-lively-code-mirror.js,
- Loading branch information
1 parent
a148ee0
commit 30fb40c
Showing
2 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,75 @@ | ||
# Code Mirror | ||
# Code Mirror Shards Sandblocks Proof of Concept | ||
|
||
## Issues: | ||
|
||
- [ ] (cursor in/out) | ||
- [ ] keep focus while typing | ||
- [X] hide line numbers | ||
- [X] hide scrollbars | ||
- [ ] update RegExp match while editing | ||
|
||
|
||
## Probe Example | ||
|
||
<script> | ||
|
||
customElements.define( | ||
"probe-widget", | ||
class extends HTMLElement { | ||
constructor() { | ||
super(); | ||
this.attachShadow({ mode: "open" }); | ||
this.addEventListener("keyup", evt => { | ||
// evt.preventDefault() | ||
// evt.stopPropagation() | ||
}) | ||
|
||
this.addEventListener("keydown", evt => { | ||
// evt.preventDefault() | ||
// evt.stopPropagation() | ||
}) | ||
this.shadowRoot.innerHTML = ` | ||
<div style="border: 1px solid gray">PROBE | ||
<lively-code-mirror class="shard"></lively-code-mirror> | ||
<slot></slot></div> | ||
`; | ||
} | ||
}) | ||
|
||
|
||
var outerLivelyCodeMirror = await (<lively-code-mirror></lively-code-mirror>) | ||
outerLivelyCodeMirror.value = `// example \nvar a = 3 + 4\n//end` | ||
outerLivelyCodeMirror.value = `var a = probe(3 + 4)` | ||
|
||
|
||
var debugLivelyCodeMirror = await (<lively-code-mirror></lively-code-mirror>) | ||
debugLivelyCodeMirror.editor.swapDoc(outerLivelyCodeMirror.editor.linkedDoc()) | ||
|
||
var regEx = new RegExp(/((probe\()(.*))\)/, "g"); | ||
do { | ||
var m = regEx.exec(outerLivelyCodeMirror.value); | ||
if (m) { | ||
var from = m.index | ||
var to = m.index + m[0].length | ||
|
||
|
||
var innerFrom = m.index + m[2].length | ||
var innerTo = m.index + m[1].length | ||
var editor = outerLivelyCodeMirror.editor | ||
|
||
var comp = await outerLivelyCodeMirror.wrapWidget("probe-widget", | ||
editor.posFromIndex(from), | ||
editor.posFromIndex(to)) | ||
|
||
var innerLivelyCodeMirror = comp.shadowRoot.querySelector("lively-code-mirror") | ||
innerLivelyCodeMirror.editor.swapDoc(editor.linkedDoc()) | ||
const opts = {collapsed: true, clearWhenEmpty: false, inclusiveLeft: false, inclusiveRight: true}; | ||
innerLivelyCodeMirror.editor.getDoc().markText(editor.posFromIndex(-1), editor.posFromIndex(innerFrom), opts); | ||
innerLivelyCodeMirror.editor.getDoc().markText(editor.posFromIndex(innerTo), editor.posFromIndex(innerLivelyCodeMirror.value.length), opts); | ||
|
||
|
||
debugger | ||
} | ||
} while (m); | ||
|
||
outerLivelyCodeMirror | ||
(<div>{outerLivelyCodeMirror}DEBUG:{debugLivelyCodeMirror}</div>) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters