Skip to content

Commit

Permalink
more tweaking and notes...
Browse files Browse the repository at this point in the history
Signed-off-by: Alex A. Naanou <[email protected]>
  • Loading branch information
flynx committed Nov 6, 2023
1 parent 8df2906 commit df8d146
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
30 changes: 20 additions & 10 deletions experiments/outline-editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ function clickPoint(x,y){
// box corresponds the to desired coordinates. This accounts for nested
// elements.
//
// XXX it would be a better idea to do a binary search instead of a liner
// pass...
// ...though b-search will get us to the target, we stll need to count...
var getCharOffset = function(elem, x, y, data={}){
// XXX do a binary search??
var getCharOffset = function(elem, x, y, data){
data = data ?? {}
var r = document.createRange()
var elem_rect = data.elem_rect =
data.elem_rect
Expand All @@ -44,7 +43,7 @@ var getCharOffset = function(elem, x, y, data={}){
data.c
?? 0
var prev, rect, cursor_line, line_start, offset
for(var i=0; i <= e.length; i++){
for(var i=0; i < e.length; i++){
r.setStart(e, i)
r.setEnd(e, i)
prev = rect
Expand Down Expand Up @@ -78,6 +77,7 @@ var getCharOffset = function(elem, x, y, data={}){
if(cursor_line){
return offset } } }
data.c += i
data.last = e.data[i-1]
// html node...
} else {
prev = data.prev =
Expand All @@ -89,13 +89,22 @@ var getCharOffset = function(elem, x, y, data={}){
&& prev.y <= y
&& prev.bottom >= y
// line break...
&& prev.y < e.getBoundingClientRect().y){
return data.c - 2 }
&& prev.y < e.getBoundingClientRect().y
// no whitespace at end, no compensation needed... (XXX test)
&& ' \t\n'.includes(data.last)){
return data.c - 1 }
// block element -- compensate for a lacking '\n'...
if(['block', 'table', 'flex', 'grid']
.includes(
getComputedStyle(e).display)){
data.c += 1 }
// handle the node...
data = getCharOffset(e, x, y, data)
if(typeof(data) != 'object'){
return data } } }
// no result was found...
console.log('---', data)
return data.c ?? data
return arguments.length > 3 ?
data
: null }
Expand All @@ -114,8 +123,8 @@ var getMarkdownOffset = function(markdown, text, i){
i = i ?? text.length
var m = 0
// walk both strings skipping/counting non-matching stuff...
for(var n=0; n <= i; n++, m++){
var c = text[n]
for(var t=0; t <= i; t++, m++){
var c = text[t]
var p = m
// walk to next match...
while(c != markdown[m] && m < markdown.length){
Expand All @@ -124,7 +133,7 @@ var getMarkdownOffset = function(markdown, text, i){
// entity, symbol, ...)
if(m >= markdown.length){
m = p } }
return m - n }
return m - t }



Expand Down Expand Up @@ -2064,6 +2073,7 @@ var Outline = {
var initial = elem.selectionStart
var c = getCharOffset(view, evt.clientX, evt.clientY)
var m = getMarkdownOffset(elem.value, view.innerText, c)
console.log('---', c, m)
// selecting an element with text offset by markup...
if(m != 0){
evt.preventDefault()
Expand Down
26 changes: 24 additions & 2 deletions experiments/outline-editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,38 @@
block element
</div>
this line, and above placement of completely broken
- _this seems to ba an issue with: `.getMarkdownOffset(..)`_
- _this seems to be an issue with: `.getMarkdownOffset(..)`_
- ```
m = `text text text
<div>
block element
</div>
this line, and above placement of completely broken`
t = 'text text text\n\n\nblock element\n\n\nthis line, and above placement of completely broken '
getMarkdownOffset(m, t, 26)
```
this returns `69` while it should return `5`
_...replacing `\n\n\n` with `\n\n` seems to fix the issue_
(BUG also the above line is not italic -- can't reproduce)
- DONE clicking right of this line will select last line of block
```
text text text
```
this line, placement is offset by 2
- DONE text text text
_text text text_
text text text
- DONE M
M can't place cursor before first char
M
- DONE inline `elements` now work
- BUG: parser: code blocks do not ignore single back-quotes...
- ```
x = `moo`
```
- _this also leads to double quoting of html..._
```
x = `<i>moo</i>`
```
- BUG: mobile browsers behave quite chaotically ignoring parts of the styling...
- FF:
- zooming on edited field
Expand Down

0 comments on commit df8d146

Please sign in to comment.