mirror of
				https://github.com/flynx/pWiki.git
				synced 2025-10-31 02:50:08 +00:00 
			
		
		
		
	more tweaking and notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									8df290604c
								
							
						
					
					
						commit
						df8d14690e
					
				| @ -29,10 +29,9 @@ 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 it would be a better idea to do a binary search instead of a liner 
 | // XXX do a binary search?? 
 | ||||||
| // 		pass...
 | var getCharOffset = function(elem, x, y, data){ | ||||||
| // 		...though b-search will get us to the target, we stll need to count...
 | 	data = data ?? {} | ||||||
| var getCharOffset = function(elem, x, y, data={}){ |  | ||||||
| 	var r = document.createRange() | 	var r = document.createRange() | ||||||
| 	var elem_rect = data.elem_rect =  | 	var elem_rect = data.elem_rect =  | ||||||
| 		data.elem_rect  | 		data.elem_rect  | ||||||
| @ -44,7 +43,7 @@ var getCharOffset = function(elem, x, y, data={}){ | |||||||
| 				data.c  | 				data.c  | ||||||
| 					?? 0 | 					?? 0 | ||||||
| 			var prev, rect, cursor_line, line_start, offset | 			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.setStart(e, i) | ||||||
| 				r.setEnd(e, i) | 				r.setEnd(e, i) | ||||||
| 				prev = rect  | 				prev = rect  | ||||||
| @ -78,6 +77,7 @@ var getCharOffset = function(elem, x, y, data={}){ | |||||||
| 					if(cursor_line){ | 					if(cursor_line){ | ||||||
| 						return offset } } } | 						return offset } } } | ||||||
| 			data.c += i | 			data.c += i | ||||||
|  | 			data.last = e.data[i-1] | ||||||
| 		// html node...
 | 		// html node...
 | ||||||
| 		} else { | 		} else { | ||||||
| 			prev = data.prev =  | 			prev = data.prev =  | ||||||
| @ -89,13 +89,22 @@ var getCharOffset = function(elem, x, y, data={}){ | |||||||
| 					&& prev.y <= y  | 					&& prev.y <= y  | ||||||
| 					&& prev.bottom >= y | 					&& prev.bottom >= y | ||||||
| 					// line break...
 | 					// line break...
 | ||||||
| 					&& prev.y < e.getBoundingClientRect().y){ | 					&& prev.y < e.getBoundingClientRect().y | ||||||
| 				return data.c - 2 } | 					// 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...
 | 			// 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...
 | 	// no result was found...
 | ||||||
|  | 	console.log('---', data) | ||||||
|  | 	return data.c ?? data | ||||||
| 	return arguments.length > 3 ? | 	return arguments.length > 3 ? | ||||||
| 		data | 		data | ||||||
| 		: null } | 		: null } | ||||||
| @ -114,8 +123,8 @@ var getMarkdownOffset = function(markdown, text, i){ | |||||||
| 	i = i ?? text.length | 	i = i ?? text.length | ||||||
| 	var m = 0 | 	var m = 0 | ||||||
| 	// walk both strings skipping/counting non-matching stuff...
 | 	// walk both strings skipping/counting non-matching stuff...
 | ||||||
| 	for(var n=0; n <= i; n++, m++){ | 	for(var t=0; t <= i; t++, m++){ | ||||||
| 		var c = text[n] | 		var c = text[t] | ||||||
| 		var p = m | 		var p = m | ||||||
| 		// walk to next match...
 | 		// walk to next match...
 | ||||||
| 		while(c != markdown[m] && m < markdown.length){ | 		while(c != markdown[m] && m < markdown.length){ | ||||||
| @ -124,7 +133,7 @@ var getMarkdownOffset = function(markdown, text, i){ | |||||||
| 		// entity, symbol, ...)
 | 		// entity, symbol, ...)
 | ||||||
| 		if(m >= markdown.length){ | 		if(m >= markdown.length){ | ||||||
| 			m = p } } | 			m = p } } | ||||||
| 	return m - n } | 	return m - t } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -2064,6 +2073,7 @@ var Outline = { | |||||||
| 					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, view.innerText, c) | ||||||
|  | 					console.log('---', c, m) | ||||||
| 					// 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() | ||||||
|  | |||||||
| @ -55,16 +55,38 @@ 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 | ||||||
|         - _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 |       - DONE clicking right of this line will select last line of block | ||||||
|         ``` |         ``` | ||||||
|         text text text |         text text text | ||||||
|         ``` |         ``` | ||||||
|         this line, placement is offset by 2 |         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 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... |   - BUG: mobile browsers behave quite chaotically ignoring parts of the styling... | ||||||
|     - FF: |     - FF: | ||||||
|       - zooming on edited field |       - zooming on edited field | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user