mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-25 12:21:58 +00:00
Compare commits
4 Commits
33961a0b3f
...
44fb61bb46
| Author | SHA1 | Date | |
|---|---|---|---|
| 44fb61bb46 | |||
| 1400050cef | |||
| b0dc4a39cc | |||
| 0e7b7dee32 |
@ -44,11 +44,6 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
?? 0
|
?? 0
|
||||||
// text node...
|
// text node...
|
||||||
if(e instanceof Text){
|
if(e instanceof Text){
|
||||||
// count "virtual" newlines between text and block elements...
|
|
||||||
if(data.prev_elem == 'block'){
|
|
||||||
data.c += 1 }
|
|
||||||
data.prev_elem = 'text'
|
|
||||||
|
|
||||||
var rect, cursor_line, line_start, offset
|
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)
|
||||||
@ -101,34 +96,9 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
&& ' \t\n'.includes(data.last)){
|
&& ' \t\n'.includes(data.last)){
|
||||||
return data.c - 1 }
|
return data.c - 1 }
|
||||||
|
|
||||||
// count "virtual" newlines between text and block elements...
|
|
||||||
var type = getComputedStyle(e).display
|
|
||||||
var block = [
|
|
||||||
'block',
|
|
||||||
// XXX these do not add up yet...
|
|
||||||
//'table',
|
|
||||||
//'table-row',
|
|
||||||
//'table-cell',
|
|
||||||
'flex',
|
|
||||||
'grid',
|
|
||||||
].includes(type)
|
|
||||||
if(block
|
|
||||||
&& data.prev_elem
|
|
||||||
&& data.prev_elem != 'block'){
|
|
||||||
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)
|
||||||
|
|
||||||
// compensate for table stuff...
|
|
||||||
if(type == 'table-row'){
|
|
||||||
data.c -= 1 }
|
|
||||||
if(type == 'table-cell'){
|
|
||||||
data.c += 1 }
|
|
||||||
|
|
||||||
if(typeof(data) != 'object'){
|
if(typeof(data) != 'object'){
|
||||||
return data } } }
|
return data } } }
|
||||||
return arguments.length > 3 ?
|
return arguments.length > 3 ?
|
||||||
@ -146,8 +116,7 @@ var getCharOffset = function(elem, x, y, data){
|
|||||||
// |
|
// |
|
||||||
// markdown: '# Hea|ding'
|
// markdown: '# Hea|ding'
|
||||||
//
|
//
|
||||||
// XXX we are not checking both lengths of markdown AND text...
|
// XXX should this be replaced with offsetAt(..)???
|
||||||
// XXX
|
|
||||||
var getMarkdownOffset = function(markdown, text, i){
|
var getMarkdownOffset = function(markdown, text, i){
|
||||||
i = i ?? text.length
|
i = i ?? text.length
|
||||||
var m = 0
|
var m = 0
|
||||||
@ -163,40 +132,17 @@ var getMarkdownOffset = function(markdown, text, i){
|
|||||||
if(m >= markdown.length){
|
if(m >= markdown.length){
|
||||||
m = p } }
|
m = p } }
|
||||||
return m - t }
|
return m - t }
|
||||||
/*/
|
|
||||||
// XXX when one string is guaranteed to be a strict subset of the other
|
|
||||||
// this is trivial, but in the general case we can have differences
|
|
||||||
// both ways, for example the "virtual" newlines added by block
|
|
||||||
// elements mess up the text...
|
|
||||||
// ...so this in the current form is fundamentally broken as skipping
|
|
||||||
// chars in text can lead to false positives and lots of potential
|
|
||||||
// (not implemented) backtracking...
|
|
||||||
// ...needs thought...
|
|
||||||
// Q: can we cheat with this? =)
|
|
||||||
// XXX BUG: clicking right of last line places the caret before the last char...
|
|
||||||
var getMarkdownOffset = function(markdown, text, i){
|
|
||||||
i = i ?? text.length
|
|
||||||
var map = []
|
|
||||||
for(var t=0, m=0; t <= text.length; t++, m++){
|
|
||||||
var o = 0
|
|
||||||
while(text[t] != markdown[m+o]
|
|
||||||
&& m+o < markdown.length){
|
|
||||||
o++ }
|
|
||||||
if(m+o >= markdown.length){
|
|
||||||
m--
|
|
||||||
} else {
|
|
||||||
m += o }
|
|
||||||
map[t] = m - t
|
|
||||||
}
|
|
||||||
return map[i] }
|
|
||||||
//*/
|
|
||||||
|
|
||||||
var getText = function(elem, res=[]){
|
// NOTE: this is the same as .innerText but will not add extra "\n" after
|
||||||
|
// each block element...
|
||||||
|
var getTexts = function(elem, res=[]){
|
||||||
for(var n of elem.childNodes){
|
for(var n of elem.childNodes){
|
||||||
n.nodeType == n.TEXT_NODE ?
|
n.nodeType == n.TEXT_NODE ?
|
||||||
res.push(n.textContent)
|
res.push(n.textContent)
|
||||||
: getText(n, res) }
|
: getTexts(n, res) }
|
||||||
return res }
|
return res }
|
||||||
|
var getText = function(elem){
|
||||||
|
return getTexts(elem).join('') }
|
||||||
|
|
||||||
var offsetAt = function(A, B, i){
|
var offsetAt = function(A, B, i){
|
||||||
i ??= A.length-1
|
i ??= A.length-1
|
||||||
@ -229,6 +175,7 @@ var offsetAt = function(A, B, i){
|
|||||||
// // this should reproduce common sections...
|
// // this should reproduce common sections...
|
||||||
// console.log('---', o.map(function(e, i){ return m[i+e] }).join(''))
|
// console.log('---', o.map(function(e, i){ return m[i+e] }).join(''))
|
||||||
// XXX can we cheat here???
|
// XXX can we cheat here???
|
||||||
|
// XXX do we need this???
|
||||||
var offsetMap = function(A, B, m=[]){
|
var offsetMap = function(A, B, m=[]){
|
||||||
var o = 0
|
var o = 0
|
||||||
var p = 0
|
var p = 0
|
||||||
@ -246,31 +193,6 @@ var offsetMap = function(A, B, m=[]){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
// find all common sections...
|
|
||||||
// XXX test...
|
|
||||||
function cs(A, B){
|
|
||||||
var map = []
|
|
||||||
for(var i=0; i < A.length; i++){
|
|
||||||
for(var j=0; j < B.length; j++){
|
|
||||||
var l = 0
|
|
||||||
while(A[i+j+l] == B[j+l]
|
|
||||||
&& j+l < B.length){
|
|
||||||
l++ }
|
|
||||||
if(l > 0){
|
|
||||||
map.push([i, j, l])
|
|
||||||
// Q: can we skip here? ...will skipping
|
|
||||||
// prevent matching "ababc" with "abc"??
|
|
||||||
j += l } } }
|
|
||||||
return map }
|
|
||||||
|
|
||||||
// build chains of blocks with their lengths...
|
|
||||||
function comb(map){
|
|
||||||
XXX
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
// Plugins...
|
// Plugins...
|
||||||
|
|
||||||
@ -2492,7 +2414,7 @@ var Outline = {
|
|||||||
var view = that.get(elem).querySelector('.view')
|
var view = that.get(elem).querySelector('.view')
|
||||||
var initial = elem.selectionStart
|
var initial = elem.selectionStart
|
||||||
var c = getCharOffset(view, evt.clientX, evt.clientY)
|
var c = getCharOffset(view, evt.clientX, evt.clientY)
|
||||||
var m = getMarkdownOffset(elem.value, view.innerText, c)
|
var m = getMarkdownOffset(elem.value, getText(view), c)
|
||||||
// selecting an element with text offset by markup...
|
// selecting an element with text offset by markup...
|
||||||
if(m != 0){
|
if(m != 0){
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
|
|||||||
@ -48,13 +48,24 @@ var setup = function(){
|
|||||||
-
|
-
|
||||||
- ## Bugs:
|
- ## Bugs:
|
||||||
focused:: true
|
focused:: true
|
||||||
- BUG: caret positioning broken
|
- DONE BUG: caret positioning broken (ASAP CLEANUP: GETTEXT)
|
||||||
- new strategy: try and build offset maps on parse...
|
collapsed:: true
|
||||||
|
- Strategies to test::
|
||||||
|
- ASAP use `getText(..)` to build the input text instead of `.innerText`
|
||||||
|
- DONE adds 1 char offset per block element
|
||||||
|
- this greatly simplifies things...
|
||||||
|
- normalize `.innerText` to remove duplicate `"\n"`'s
|
||||||
|
_(will break placement on empty lines... ???)_
|
||||||
|
- try and build offset maps on parse
|
||||||
|
_(potentially too complicated)_
|
||||||
- *TODO*::
|
- *TODO*::
|
||||||
|
- *DONE*::
|
||||||
|
collapsed:: true
|
||||||
- ```
|
- ```
|
||||||
text text text
|
text text text
|
||||||
```
|
```
|
||||||
text text text (a click here is offset right)
|
text text text (a click here is offset right)
|
||||||
|
collapsed:: true
|
||||||
- the offset's amount depends on where in the text we click after the code block, the farther right the greater the offset...
|
- the offset's amount depends on where in the text we click after the code block, the farther right the greater the offset...
|
||||||
- `getCharOffset(..)` produces correct results, the problem is in `getMarkdownOffset(..)`
|
- `getCharOffset(..)` produces correct results, the problem is in `getMarkdownOffset(..)`
|
||||||
- text text text
|
- text text text
|
||||||
@ -62,6 +73,7 @@ var setup = function(){
|
|||||||
block element
|
block element
|
||||||
</div>
|
</div>
|
||||||
this line, and above placement of completely broken
|
this line, and above placement of completely broken
|
||||||
|
collapsed:: true
|
||||||
- the odd thing is that a nested (bug) qupted text below also breaks...
|
- the odd thing is that a nested (bug) qupted text below also breaks...
|
||||||
- _this seems to be an issue with: `.getMarkdownOffset(..)`_
|
- _this seems to be an issue with: `.getMarkdownOffset(..)`_
|
||||||
- ```
|
- ```
|
||||||
@ -76,8 +88,6 @@ 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*::
|
|
||||||
collapsed:: true
|
|
||||||
- text text text
|
- text text text
|
||||||
- text text text
|
- text text text
|
||||||
text text text
|
text text text
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user