优化编辑器功能

This commit is contained in:
shijian 2023-09-30 02:02:35 +08:00
parent f75c726656
commit d1e0022a62
1 changed files with 68 additions and 52 deletions

View File

@ -40951,18 +40951,19 @@
} }
//创建ul列表 //创建ul列表
const createMenu=function(pos,self,List,click){ const createMenu=function(pos,self,List,click){
if (self&&self.createMenu) { if(!self||self==window) return;
createList.push(self.createMenu);
ui.window.appendChild(self.createMenu);
return self.createMenu;
}
const parent=self.parentNode; const parent=self.parentNode;
if (parent){ if (parent){
for(let i=0;i<parent.childElementCount;i++){ for(let i=0;i<parent.childElementCount;i++){
const node=parent.childNodes[i]; const node=parent.childNodes[i];
node!=self&&node.createMenu&&closeMenu.call(node); if(node!=self&&node.createMenu) closeMenu.call(node);
} }
} }
if(self.createMenu){
createList.push(self.createMenu);
ui.window.appendChild(self.createMenu);
return self.createMenu;
}
const editor=container.editor; const editor=container.editor;
if(!editor) return false; if(!editor) return false;
self.style.background='#08f'; self.style.background='#08f';
@ -40974,7 +40975,7 @@
height:'20em', height:'20em',
width:pos.width*4/game.documentZoom+'px', width:pos.width*4/game.documentZoom+'px',
//'font-family':'shousha', //'font-family':'shousha',
'font-size':(lib.config.codeMirror_fontSize?lib.config.codeMirror_fontSize.slice(-2):16)/game.documentZoom+'px', 'font-size':(lib.config.codeMirror_fontSize?lib.config.codeMirror_fontSize.slice(0,-2):16)/game.documentZoom+'px',
}); });
const theme=editor.options.theme; const theme=editor.options.theme;
@ -41019,7 +41020,7 @@
}; };
} }
} }
createList.push(ul); createList.add(ul);
ui.window.appendChild(ul); ui.window.appendChild(ul);
return ul; return ul;
}; };
@ -41043,19 +41044,21 @@
}); });
const saveConfig=ui.create.div('.editbutton','保存',editorpage,saveInput); const saveConfig=ui.create.div('.editbutton','保存',editorpage,saveInput);
const theme=ui.create.div('.editbutton','主题',editorpage,function(){ const theme=ui.create.div('.editbutton','主题',editorpage,function(){
if(this&&this.createMenu&&this.createMenu.parentNode){ if(!this||this==window) return;
if(this.createMenu&&this.createMenu.parentNode){
return closeMenu.call(this); return closeMenu.call(this);
} }
//this
const self=this;
if(!this.createMenu){
//主题列表 //主题列表
const list=['mdn-like','mbo']; const list=['mdn-like','mbo'];
//正在使用的主题 //正在使用的主题
const active=container.editor.options.theme; const active=container.editor.options.theme;
//排个序 //排个序
list.remove(active).splice(0,0,active); list.remove(active).splice(0,0,active);
//this
const self=this;
//元素位置 //元素位置
const pos=this.getBoundingClientRect(); const pos=self.getBoundingClientRect();
//点击事件 //点击事件
const click=function(e){ const click=function(e){
const theme=this.innerHTML; const theme=this.innerHTML;
@ -41065,13 +41068,18 @@
closeMenu.call(self); closeMenu.call(self);
}; };
const ul=createMenu(pos,self,list,click); const ul=createMenu(pos,self,list,click);
this.createMenu=ul; self.createMenu=ul;
}else{
createMenu(null,self);
}
}); });
const edit=ui.create.div('.editbutton','编辑',editorpage,function(){ const edit=ui.create.div('.editbutton','编辑',editorpage,function(){
if(this&&this.createMenu&&this.createMenu.parentNode){ if(!this||this==window) return;
if(this.createMenu&&this.createMenu.parentNode){
return closeMenu.call(this); return closeMenu.call(this);
} }
const self=this; const self=this;
if(!this.createMenu){
const pos=this.getBoundingClientRect(); const pos=this.getBoundingClientRect();
const list=['撤销 Ctrl+Z', '恢复撤销 Ctrl+Y']; const list=['撤销 Ctrl+Z', '恢复撤销 Ctrl+Y'];
const click=function(e){ const click=function(e){
@ -41083,12 +41091,17 @@
}; };
const ul=createMenu(pos,self,list,click); const ul=createMenu(pos,self,list,click);
this.createMenu=ul; this.createMenu=ul;
}else{
createMenu(null,self);
}
}); });
const fontSize=ui.create.div('.editbutton','字号',editorpage,function(){ const fontSize=ui.create.div('.editbutton','字号',editorpage,function(){
if(this&&this.createMenu&&this.createMenu.parentNode){ if(!this||this==window) return;
if(this.createMenu&&this.createMenu.parentNode){
return closeMenu.call(this); return closeMenu.call(this);
} }
const self=this; const self=this;
if(!this.createMenu){
const pos=this.getBoundingClientRect(); const pos=this.getBoundingClientRect();
const list=['16px','18px','20px','22px','24px','26px']; const list=['16px','18px','20px','22px','24px','26px'];
const click=function(e){ const click=function(e){
@ -41101,6 +41114,9 @@
}; };
const ul=createMenu(pos,self,list,click); const ul=createMenu(pos,self,list,click);
this.createMenu=ul; this.createMenu=ul;
}else{
createMenu(null,self);
}
}); });
const editor=ui.create.div(editorpage); const editor=ui.create.div(editorpage);
return editor; return editor;