mirror of
https://github.com/flynx/pWiki.git
synced 2025-10-29 10:00:08 +00:00
bugfix...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
54b7ae94ca
commit
9a0c04dbb4
@ -29,6 +29,7 @@ function clickPoint(x,y){
|
|||||||
// box corresponds the to desired coordinates. This accounts for nested
|
// box corresponds the to desired coordinates. This accounts for nested
|
||||||
// elements.
|
// elements.
|
||||||
//
|
//
|
||||||
|
// XXX can we avoid tracking "virtual" newlines between text/block elements???
|
||||||
// XXX do a binary search??
|
// XXX do a binary search??
|
||||||
var getCharOffset = function(elem, x, y, data){
|
var getCharOffset = function(elem, x, y, data){
|
||||||
data = data ?? {}
|
data = data ?? {}
|
||||||
@ -37,12 +38,18 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
data.elem_rect
|
data.elem_rect
|
||||||
?? elem.getBoundingClientRect()
|
?? elem.getBoundingClientRect()
|
||||||
for(var e of [...elem.childNodes]){
|
for(var e of [...elem.childNodes]){
|
||||||
|
var prev
|
||||||
|
var c = data.c =
|
||||||
|
data.c
|
||||||
|
?? 0
|
||||||
// text node...
|
// text node...
|
||||||
if(e instanceof Text){
|
if(e instanceof Text){
|
||||||
var c = data.c =
|
// count "virtual" newlines between text and block elements...
|
||||||
data.c
|
if(data.prev_elem == 'block'){
|
||||||
?? 0
|
data.c += 1 }
|
||||||
var prev, rect, cursor_line, line_start, offset
|
data.prev_elem = 'text'
|
||||||
|
|
||||||
|
var 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.setStart(e, i)
|
||||||
r.setEnd(e, i)
|
r.setEnd(e, i)
|
||||||
@ -66,7 +73,7 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
&& rect.x >= x){
|
&& rect.x >= x){
|
||||||
// get closest edge of element under cursor...
|
// get closest edge of element under cursor...
|
||||||
var dp = Math.abs(
|
var dp = Math.abs(
|
||||||
(line_start ?
|
((!prev || line_start) ?
|
||||||
elem_rect
|
elem_rect
|
||||||
: prev).x
|
: prev).x
|
||||||
- x)
|
- x)
|
||||||
@ -93,21 +100,27 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
// no whitespace at end, no compensation needed... (XXX test)
|
// no whitespace at end, no compensation needed... (XXX test)
|
||||||
&& ' \t\n'.includes(data.last)){
|
&& ' \t\n'.includes(data.last)){
|
||||||
return data.c - 1 }
|
return data.c - 1 }
|
||||||
// block element -- compensate for a lacking '\n'...
|
|
||||||
if(['block', 'table', 'flex', 'grid']
|
// count "virtual" newlines between text and block elements...
|
||||||
|
var block = ['block', 'table', 'flex', 'grid']
|
||||||
.includes(
|
.includes(
|
||||||
getComputedStyle(e).display)){
|
getComputedStyle(e).display)
|
||||||
|
if(block
|
||||||
|
&& data.prev_elem
|
||||||
|
&& data.prev_elem != 'block'){
|
||||||
data.c += 1 }
|
data.c += 1 }
|
||||||
|
data.prev_elem = block ?
|
||||||
|
'block'
|
||||||
|
: 'elem'
|
||||||
|
|
||||||
// handle the node...
|
// handle the node...
|
||||||
data = getCharOffset(e, x, y, data)
|
data = getCharOffset(e, x, y, data)
|
||||||
if(typeof(data) != 'object'){
|
if(typeof(data) != 'object'){
|
||||||
return data } } }
|
return data } } }
|
||||||
// no result was found...
|
|
||||||
console.log('---', data)
|
|
||||||
return data.c ?? data
|
|
||||||
return arguments.length > 3 ?
|
return arguments.length > 3 ?
|
||||||
data
|
data
|
||||||
: null }
|
// root call...
|
||||||
|
: data.c }
|
||||||
|
|
||||||
|
|
||||||
// Get offset in markdown relative to the resulting text...
|
// Get offset in markdown relative to the resulting text...
|
||||||
|
|||||||
@ -68,17 +68,23 @@ var setup = function(){
|
|||||||
this returns `69` while it should return `5`
|
this returns `69` while it should return `5`
|
||||||
_...replacing `\n\n\n` with `\n\n` seems to fix the issue (also works with spaces)_
|
_...replacing `\n\n\n` with `\n\n` seems to fix the issue (also works with spaces)_
|
||||||
(BUG also the above line is not italic -- can't reproduce)
|
(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
|
- DONE M
|
||||||
M can't place cursor before first char
|
M can't place cursor before first char
|
||||||
M
|
M
|
||||||
|
- DONE text text text
|
||||||
|
```
|
||||||
|
text text text
|
||||||
|
```
|
||||||
|
text text text
|
||||||
|
- DONE text text text
|
||||||
|
_text text text_
|
||||||
|
text text text
|
||||||
|
- DONE _text text text_
|
||||||
|
text text text
|
||||||
|
- DONE ```
|
||||||
|
text text text
|
||||||
|
```
|
||||||
|
text text text
|
||||||
- BUG: parser: code blocks do not ignore single back-quotes...
|
- BUG: parser: code blocks do not ignore single back-quotes...
|
||||||
- ```
|
- ```
|
||||||
x = `moo`
|
x = `moo`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user