fix markdown again
This commit is contained in:
parent
17d032b9ea
commit
a827ed102b
2 changed files with 32 additions and 11 deletions
|
@ -1737,7 +1737,10 @@ class Localuser{
|
||||||
console.log(replacewith);
|
console.log(replacewith);
|
||||||
console.log(original);
|
console.log(original);
|
||||||
this.typeMd.txt = raw.split("");
|
this.typeMd.txt = raw.split("");
|
||||||
this.typeMd.boxupdate(typebox);
|
const match=original.match(this.autofillregex);
|
||||||
|
if(match){
|
||||||
|
this.typeMd.boxupdate(typebox,replacewith.length-match[0].length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
MDSearchOptions(options:[string,string,void|HTMLElement][],original:string){
|
MDSearchOptions(options:[string,string,void|HTMLElement][],original:string){
|
||||||
const div=document.getElementById("searchOptions");
|
const div=document.getElementById("searchOptions");
|
||||||
|
@ -1915,6 +1918,7 @@ class Localuser{
|
||||||
this.MDSearchOptions(map,orginal);
|
this.MDSearchOptions(map,orginal);
|
||||||
}
|
}
|
||||||
search(str:string,pre:boolean){
|
search(str:string,pre:boolean){
|
||||||
|
console.log(str);
|
||||||
if(!pre){
|
if(!pre){
|
||||||
const match=str.match(this.autofillregex);
|
const match=str.match(this.autofillregex);
|
||||||
|
|
||||||
|
|
|
@ -713,8 +713,8 @@ txt[j + 1] === undefined)
|
||||||
box.onkeyup(new KeyboardEvent("_"));
|
box.onkeyup(new KeyboardEvent("_"));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
boxupdate(box: HTMLElement){
|
boxupdate(box: HTMLElement,offset=0){
|
||||||
const restore = saveCaretPosition(box);
|
const restore = saveCaretPosition(box,offset);
|
||||||
box.innerHTML = "";
|
box.innerHTML = "";
|
||||||
box.append(this.makeHTML({ keep: true }));
|
box.append(this.makeHTML({ keep: true }));
|
||||||
if(restore){
|
if(restore){
|
||||||
|
@ -829,7 +829,7 @@ txt[j + 1] === undefined)
|
||||||
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
|
//solution from https://stackoverflow.com/questions/4576694/saving-and-restoring-caret-position-for-contenteditable-div
|
||||||
let text = "";
|
let text = "";
|
||||||
let formatted=false;
|
let formatted=false;
|
||||||
function saveCaretPosition(context: HTMLElement){
|
function saveCaretPosition(context: HTMLElement,offset=0){
|
||||||
const selection = window.getSelection() as Selection;
|
const selection = window.getSelection() as Selection;
|
||||||
if(!selection)return;
|
if(!selection)return;
|
||||||
const range = selection.getRangeAt(0);
|
const range = selection.getRangeAt(0);
|
||||||
|
@ -902,7 +902,7 @@ function saveCaretPosition(context: HTMLElement){
|
||||||
build+=baseString;
|
build+=baseString;
|
||||||
}
|
}
|
||||||
text=build;
|
text=build;
|
||||||
const len=build.length;
|
const len=build.length+offset;
|
||||||
return function restore(){
|
return function restore(){
|
||||||
if(!selection)return;
|
if(!selection)return;
|
||||||
const pos = getTextNodeAtPosition(context, len);
|
const pos = getTextNodeAtPosition(context, len);
|
||||||
|
@ -933,29 +933,46 @@ function getTextNodeAtPosition(root: Node, index: number):{
|
||||||
position: -1,
|
position: -1,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
let lastElm:Node=root;
|
||||||
for(const node of root.childNodes as unknown as Node[]){
|
for(const node of root.childNodes as unknown as Node[]){
|
||||||
|
lastElm=node;
|
||||||
let len:number
|
let len:number
|
||||||
if(node instanceof HTMLElement){
|
if(node instanceof HTMLElement){
|
||||||
len=MarkDown.gatherBoxText(node).length;
|
len=MarkDown.gatherBoxText(node).length;
|
||||||
}else{
|
}else{
|
||||||
len=(node.textContent as string).length
|
len=(node.textContent as string).length
|
||||||
}
|
}
|
||||||
if(len<index){
|
if(len<=index&&(len<index||len!==0)){
|
||||||
index-=len;
|
index-=len;
|
||||||
}else{
|
}else{
|
||||||
const returny=getTextNodeAtPosition(node,index);
|
const returny=getTextNodeAtPosition(node,index);
|
||||||
if(returny.position===-1){
|
if(returny.position===-1){
|
||||||
|
console.warn("in here");
|
||||||
index=0;
|
index=0;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return returny;
|
return returny;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( !((lastElm instanceof HTMLElement && lastElm.hasAttribute("real")))){
|
||||||
|
while(lastElm&&!(lastElm instanceof Text||lastElm instanceof HTMLBRElement)){
|
||||||
|
lastElm=lastElm.childNodes[lastElm.childNodes.length-1];
|
||||||
|
}
|
||||||
|
if(lastElm){
|
||||||
|
const position=(lastElm.textContent as string).length;
|
||||||
|
console.log(lastElm,lastElm.childNodes,root,position);
|
||||||
|
return{
|
||||||
|
node: lastElm,
|
||||||
|
position
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
const span=document.createElement("span");
|
const span=document.createElement("span");
|
||||||
root.appendChild(span)
|
root.appendChild(span)
|
||||||
return{
|
return{
|
||||||
node: span,
|
node: span,
|
||||||
position: 0,
|
position: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
export{ MarkDown , saveCaretPosition, getTextNodeAtPosition};
|
export{ MarkDown , saveCaretPosition, getTextNodeAtPosition};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue