Merge pull request #428 from nonameShijian/PR-Branch
代码编辑器修改默认字体大小,增加修改字体大小功能菜单
This commit is contained in:
commit
53243798ad
112
game/game.js
112
game/game.js
|
@ -40959,14 +40959,19 @@
|
||||||
}
|
}
|
||||||
//创建ul列表
|
//创建ul列表
|
||||||
const createMenu=function(pos,self,List,click){
|
const createMenu=function(pos,self,List,click){
|
||||||
if (self&&self.createMenu) return false;
|
if(!self||self==window) return;
|
||||||
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.add(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';
|
||||||
|
@ -40978,7 +40983,8 @@
|
||||||
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':20/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;
|
||||||
lib.setScroll(ul);
|
lib.setScroll(ul);
|
||||||
|
@ -41022,7 +41028,7 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createList.push(ul);
|
createList.add(ul);
|
||||||
ui.window.appendChild(ul);
|
ui.window.appendChild(ul);
|
||||||
return ul;
|
return ul;
|
||||||
};
|
};
|
||||||
|
@ -41032,7 +41038,8 @@
|
||||||
if(!ul) return false;
|
if(!ul) return false;
|
||||||
if(ul.parentNode) ul.parentNode.removeChild(ul);
|
if(ul.parentNode) ul.parentNode.removeChild(ul);
|
||||||
this.style.background='';
|
this.style.background='';
|
||||||
delete this.createMenu;
|
//创建后不用删除了,除非以后要动态加载。
|
||||||
|
//delete this.createMenu;
|
||||||
createList.remove(ul);
|
createList.remove(ul);
|
||||||
return ul;
|
return ul;
|
||||||
};
|
};
|
||||||
|
@ -41045,46 +41052,79 @@
|
||||||
});
|
});
|
||||||
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){
|
if(!this||this==window) return;
|
||||||
|
if(this.createMenu&&this.createMenu.parentNode){
|
||||||
return closeMenu.call(this);
|
return closeMenu.call(this);
|
||||||
}
|
}
|
||||||
//主题列表
|
|
||||||
const list=['mdn-like','mbo'];
|
|
||||||
//正在使用的主题
|
|
||||||
const active=container.editor.options.theme;
|
|
||||||
//排个序
|
|
||||||
list.remove(active).splice(0,0,active);
|
|
||||||
//this
|
//this
|
||||||
const self=this;
|
const self=this;
|
||||||
//元素位置
|
if(!this.createMenu){
|
||||||
const pos=this.getBoundingClientRect();
|
//主题列表
|
||||||
//点击事件
|
const list=['mdn-like','mbo'];
|
||||||
const click=function(e){
|
//正在使用的主题
|
||||||
const theme=this.innerHTML;
|
const active=container.editor.options.theme;
|
||||||
container.editor.setOption("theme",theme);
|
//排个序
|
||||||
setTimeout(()=>container.editor.refresh(),0);
|
list.remove(active).splice(0,0,active);
|
||||||
game.saveConfig('codeMirror_theme', theme);
|
//元素位置
|
||||||
closeMenu.call(self);
|
const pos=self.getBoundingClientRect();
|
||||||
};
|
//点击事件
|
||||||
const ul=createMenu(pos,self,list,click);
|
const click=function(e){
|
||||||
this.createMenu=ul;
|
const theme=this.innerHTML;
|
||||||
|
container.editor.setOption("theme",theme);
|
||||||
|
setTimeout(()=>container.editor.refresh(),0);
|
||||||
|
game.saveConfig('codeMirror_theme',theme);
|
||||||
|
closeMenu.call(self);
|
||||||
|
};
|
||||||
|
const ul=createMenu(pos,self,list,click);
|
||||||
|
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){
|
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;
|
||||||
const pos=this.getBoundingClientRect();
|
if(!this.createMenu){
|
||||||
const list=['撤销 Ctrl+Z', '恢复撤销 Ctrl+Y'];
|
const pos=this.getBoundingClientRect();
|
||||||
const click=function(e){
|
const list=['撤销 Ctrl+Z', '恢复撤销 Ctrl+Y'];
|
||||||
const num=this.innerHTML.indexOf("Ctrl");
|
const click=function(e){
|
||||||
const inner=this.innerHTML.slice(num).replace("+", "-");
|
const num=this.innerHTML.indexOf("Ctrl");
|
||||||
container.editor.execCommand(container.editor.options.extraKeys[inner]);
|
const inner=this.innerHTML.slice(num).replace("+", "-");
|
||||||
setTimeout(()=>container.editor.refresh(),0);
|
container.editor.execCommand(container.editor.options.extraKeys[inner]);
|
||||||
closeMenu.call(self);
|
setTimeout(()=>container.editor.refresh(),0);
|
||||||
};
|
closeMenu.call(self);
|
||||||
const ul=createMenu(pos,self,list,click);
|
};
|
||||||
this.createMenu=ul;
|
const ul=createMenu(pos,self,list,click);
|
||||||
|
this.createMenu=ul;
|
||||||
|
}else{
|
||||||
|
createMenu(null,self);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const fontSize=ui.create.div('.editbutton','字号',editorpage,function(){
|
||||||
|
if(!this||this==window) return;
|
||||||
|
if(this.createMenu&&this.createMenu.parentNode){
|
||||||
|
return closeMenu.call(this);
|
||||||
|
}
|
||||||
|
const self=this;
|
||||||
|
if(!this.createMenu){
|
||||||
|
const pos=this.getBoundingClientRect();
|
||||||
|
const list=['16px','18px','20px','22px','24px','26px'];
|
||||||
|
const click=function(e){
|
||||||
|
const size=this.innerHTML;
|
||||||
|
container.style.fontSize=size.slice(0,-2)/game.documentZoom+'px';
|
||||||
|
Array.from(self.parentElement.children).map(v=>v.createMenu).filter(Boolean).forEach(v=>{v.style.fontSize=size.slice(0,-2)/game.documentZoom+'px'});
|
||||||
|
container.listenTransition(()=>container.editor.refresh());
|
||||||
|
game.saveConfig('codeMirror_fontSize',size);
|
||||||
|
closeMenu.call(self);
|
||||||
|
};
|
||||||
|
const ul=createMenu(pos,self,list,click);
|
||||||
|
this.createMenu=ul;
|
||||||
|
}else{
|
||||||
|
createMenu(null,self);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
const editor=ui.create.div(editorpage);
|
const editor=ui.create.div(editorpage);
|
||||||
return editor;
|
return editor;
|
||||||
|
|
Loading…
Reference in New Issue