mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-25 12:21:58 +00:00
Compare commits
No commits in common. "10da7885acb3bd80660e5e4f66ac4011e426ab60" and "38e90d607197619e979785b3783eb93409c0871d" have entirely different histories.
10da7885ac
...
38e90d6071
@ -29,55 +29,52 @@ 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 with multi-line text when clicking outside the text to the left/right
|
||||||
|
// need to select the appropriate line...
|
||||||
// XXX it would be a better idea to do a binary search instead of a liner
|
// XXX it would be a better idea to do a binary search instead of a liner
|
||||||
// pass...
|
// pass...
|
||||||
// ...though b-search will get us to the target, we stll need to count...
|
// ...though b-search will get us to the target, we stll need to count...
|
||||||
var getCharOffset = function(elem, x, y, options={}){
|
// XXX HACK -- is there a better way to do this???
|
||||||
|
var getCharOffset = function(elem, x, y, c){
|
||||||
|
c = c ?? 0
|
||||||
var r = document.createRange()
|
var r = document.createRange()
|
||||||
for(var e of [...elem.childNodes]){
|
for(var e of [...elem.childNodes]){
|
||||||
var c = options.c ?? 0
|
|
||||||
// text node...
|
// text node...
|
||||||
if(e instanceof Text){
|
if(e instanceof Text){
|
||||||
var prev, rect, cursor_line, col
|
var prev, b
|
||||||
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)
|
||||||
prev = rect
|
prev = b
|
||||||
?? options.prev
|
b = r.getBoundingClientRect()
|
||||||
rect = r.getBoundingClientRect()
|
// found target...
|
||||||
// line change...
|
if(b.x >= x
|
||||||
// NOTE: this is almost identical to .getTextOffsetAt(..) see
|
&& b.y <= y
|
||||||
// that for more docs...
|
&& b.bottom >= y){
|
||||||
if(prev
|
// get the closest gap between chars to the click...
|
||||||
&& prev.y != rect.y){
|
return (!prev
|
||||||
if(cursor_line){
|
|| Math.abs(b.x - x) <= Math.abs(prev.x - x)) ?
|
||||||
return col
|
|
||||||
?? c + i - 2 }
|
|
||||||
col = undefined }
|
|
||||||
cursor_line =
|
|
||||||
rect.y <= y
|
|
||||||
&& rect.bottom >= y
|
|
||||||
if(col == null
|
|
||||||
&& rect.x >= x){
|
|
||||||
col = (c + i == 0
|
|
||||||
|| Math.abs(rect.x - x) <= Math.abs(prev.x - x)) ?
|
|
||||||
c + i
|
c + i
|
||||||
: c + i - 1
|
: c + i - 1 } }
|
||||||
if(cursor_line){
|
c += i - 1
|
||||||
return col } } }
|
|
||||||
options.c += c - 1
|
|
||||||
// html node...
|
// html node...
|
||||||
} else {
|
} else {
|
||||||
options.prev = prev
|
var res = getCharOffset(e, x, y, c)
|
||||||
options = getCharOffset(e, x, y, options)
|
if(!(res instanceof Array)){
|
||||||
if(typeof(options) != 'object'){
|
return res }
|
||||||
return options } } }
|
;[c, res] = res } }
|
||||||
// no result was found...
|
// no result was found...
|
||||||
return arguments.length > 3 ?
|
return arguments.length > 3 ?
|
||||||
options
|
[c, null]
|
||||||
: null }
|
: null }
|
||||||
|
|
||||||
|
|
||||||
|
var getTextAreaOffset = function(elem, x, y){
|
||||||
|
return elem.getTextGeometry(function(res, elem){
|
||||||
|
// XXX this will not work as it needs correct placement of elem under the cursor...
|
||||||
|
return getCharOffset(elem, x, y) }) }
|
||||||
|
|
||||||
|
|
||||||
// Get offset in markdown relative to the resulting text...
|
// Get offset in markdown relative to the resulting text...
|
||||||
//
|
//
|
||||||
// v <----- position
|
// v <----- position
|
||||||
|
|||||||
@ -198,6 +198,7 @@ HTMLTextAreaElement.prototype.getTextOffsetAt = function(x, y){
|
|||||||
// cursor col -- set once per line...
|
// cursor col -- set once per line...
|
||||||
if(col == null
|
if(col == null
|
||||||
&& ox <= rect.x - clone.x){
|
&& ox <= rect.x - clone.x){
|
||||||
|
// XXX not sure about this test...
|
||||||
col = (ox > 0
|
col = (ox > 0
|
||||||
|| i == 0) ?
|
|| i == 0) ?
|
||||||
i
|
i
|
||||||
|
|||||||
@ -48,6 +48,13 @@ var setup = function(){
|
|||||||
-
|
-
|
||||||
- ## Bugs:
|
- ## Bugs:
|
||||||
focused:: true
|
focused:: true
|
||||||
|
- BUG? clicking a block right of the lines places the cursor at end of last line -- should be the end of the cursor line (see: `.getTextOffsetAt(..)`)
|
||||||
|
- example click right of the text:
|
||||||
|
- example text
|
||||||
|
example text
|
||||||
|
example text
|
||||||
|
example text
|
||||||
|
- _appears that the initial caret placement is correct, but then it gets moved to the end of the block..._
|
||||||
- BUG: mobile browsers behave quite chaotically ignoring parts of the styling...
|
- BUG: mobile browsers behave quite chaotically ignoring parts of the styling...
|
||||||
- FF:
|
- FF:
|
||||||
- zooming on edited field
|
- zooming on edited field
|
||||||
@ -56,7 +63,6 @@ var setup = function(){
|
|||||||
- side margins are a bit too large (account for toolbat to the right)
|
- side margins are a bit too large (account for toolbat to the right)
|
||||||
-
|
-
|
||||||
- ## ToDo:
|
- ## ToDo:
|
||||||
- Q: can we place a cursor in a table correctly???
|
|
||||||
- custom element / web component
|
- custom element / web component
|
||||||
- BUG: select via double/triple clicks does not work...
|
- BUG: select via double/triple clicks does not work...
|
||||||
- _looks like something is refocusing the element..._
|
- _looks like something is refocusing the element..._
|
||||||
@ -78,8 +84,6 @@ var setup = function(){
|
|||||||
- DONE multiple node selection (via shift+motion)
|
- DONE multiple node selection (via shift+motion)
|
||||||
- fixed state -- while `shift` pressed select or deselect only depending on first action (a-la FAR)
|
- fixed state -- while `shift` pressed select or deselect only depending on first action (a-la FAR)
|
||||||
- DONE double/triple click working...
|
- DONE double/triple click working...
|
||||||
- delete
|
|
||||||
- copy/cut/past (???)
|
|
||||||
- touch/mouse (???)
|
- touch/mouse (???)
|
||||||
- Q: should we select text (mouse/touch) without first focusing??
|
- Q: should we select text (mouse/touch) without first focusing??
|
||||||
- _...logseq does not do this either_
|
- _...logseq does not do this either_
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user