Lively Kernel canvas
//
10000.2567136883199688Wikicontroltrue
FixCommandKey40
10000.000001491432964423038Wikicontroltrue
10000.0022185844923339956Wikicontroltrue
-----falsetruefalse0
fontCourier12:spacewidth7from21xWidth7falsetruefalse0
worldis1:WorldMorph([[0,0,2000,1200]])falsetruefalse0
startingWikiNavigatorfalsetruefalse0
status207onPROPFINDhttp://www.lively-kernel.org/repository/webwerkstatt/draft/FixCommandKey.xhtmlfalsetruefalse0
http://www.lively-kernel.org/repository/webwerkstatt/draft/../anonymous_module_3loadedin33msfalsetruefalse0
http://www.lively-kernel.org/repository/webwerkstatt/draft/../anonymous_module_2loadedin682msfalsetruefalse0
fontHelvetica40:spacewidth4076from4116xWidth20falsetruefalse0
fitWidthfailureonTextMorph.getCharBoundsfalsetruefalse0
fontHelvetica15:spacewidth4from20xWidth8falsetruefalse0
fontHelvetica16:spacewidth1637from1653xWidth8falsetruefalse0
fitWidthfailureonTextMorph.getCharBoundsfalsetruefalse0
ResizingSVGcanvasfalsetruefalse0
LayerBugFixLayerisalreadytherefalsetruefalse0
Moduleloadcheckdone.29modulesloaded.falsetruefalse0
-------------------------------------------falsetruefalse0
invoke1:WorldMorph([[0,0,2000,1200]])falsetruefalse0
status200onGEThttp://www.lively-kernel.org/repository/webwerkstatt/draft/FixCommandKey.xhtmlfalsetruefalse0
extendForSerializationundefinedfalsetruefalse01137.0899560546875-1nulltrue0false
truetruefalse
false1truefalse
nullfalse
nullfalse
nullfalse
nullfalsefalsetruetruefalse
truetrue100false
truefalsenull050
nullfalsetruenullfalse
Consolefalsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
10006.33651213428468e-17Wikicontroltrue
$morph('TestMorph')$morph('TestMorph').setWithLayers([BugFixLayer])truetruefalse3truetruefalse
false1truefalsetruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
3+4console.log("Hello")151
10004.887733590516009Wikicontroltrue
ThedefaultEventhandlersthatopenforexampletheprintdialogcanbestopped,sowecanusethedefaultsystemmodifierkeys:CtrlandMeta.162
10003.5248869000000003Wikicontroltrue
createLayer("BugFixLayer")layerClass(BugFixLayer,TextMorph,{onKeyDown:function(proceed,evt){//console.log("onKeyDown"+evt);if(!this.acceptInput)return;//rk:WithMacOS10.6it'snotsufficienttosettheselectionofthetextarea//whendoingtryClipboardAction.Hackofthehackfornow:alwayssetselection//FIXME,otherplaceWidgets,SelectionMorph>>reshapeClipboardHack.selectPasteBuffer();varselecting=evt.isShiftDown();varselectionStopped=!this.hasNullSelection()&&!selecting;varpos=this.getCursorPos();//isselectionRange[0]orselectionRange[1],dependsonselectionPivotvarwordRange=evt.isMetaDown()?this.locale.selectWord(this.textString,pos):null;vartextMorph=this;varmoveCursor=function(newPos){if(selecting)textMorph.extendSelection(newPos);elsetextMorph.startSelection(newPos);evt.stop();returntrue;};switch(evt.getKeyCode()){caseEvent.KEY_HOME:{//gotothebeginningofthelinevarline=this.lines[this.lineNumberForIndex(pos)]||this.lines.last();//FIXMEreturnmoveCursor(line.startIndex);}caseEvent.KEY_END:{//gototheendofthelinevarline=this.lines[this.lineNumberForIndex(pos)]||this.lines.last();//FIXMEvaridx=line===this.lines.last()?line.getStopIndex()+1:line.getStopIndex();//FIXME!!!returnmoveCursor(idx);}caseEvent.KEY_PAGEUP:{//gotostartreturnmoveCursor(0);}caseEvent.KEY_PAGEDOWN:{//gotostartreturnmoveCursor(this.textString.length);}caseEvent.KEY_LEFT:{if(selectionStopped)//ifaselectionexistsbutbutselectingoff->jumptothebeginningoftheselectionreturnmoveCursor(this.selectionRange[0]);varnewPos=evt.isMetaDown()&&wordRange[0]!=pos?wordRange[0]:pos-1;newPos=Math.max(newPos,0);returnmoveCursor(newPos);}caseEvent.KEY_RIGHT:{if(selectionStopped)//ifaselectionexistsbutselectingoff->jumptotheendoftheselectionreturnmoveCursor(this.selectionRange[1]+1);newPos=evt.isMetaDown()&&wordRange[1]+1!=pos?wordRange[1]+1:pos+1;newPos=Math.min(this.textString.length,newPos);returnmoveCursor(newPos);}caseEvent.KEY_UP:{varlineNo=this.lineNumberForIndex(Math.min(pos,this.textString.length-1));if(lineNo<=0){//cannotmoveupevt.stop();returntrue;}varline=this.lines[lineNo];varlineIndex=pos-line.startIndex;varnewLine=this.lines[lineNo-1];varnewPos=Math.min(newLine.startIndex+lineIndex,newLine.getStopIndex());returnmoveCursor(newPos);}caseEvent.KEY_DOWN:{varlineNo=this.lineNumberForIndex(pos);if(lineNo>=this.lines.length-1){//cannotmovedownevt.stop();returntrue;}varline=this.lines[lineNo];if(!line){console.log('TextMorphfindsnoline???');evt.stop();returntrue}varlineIndex=pos-line.startIndex;varnewLine=this.lines[lineNo+1];varnewPos=Math.min(newLine.startIndex+lineIndex,newLine.getStopIndex());returnmoveCursor(newPos);}caseEvent.KEY_TAB:{this.replaceSelectionfromKeyboard("\t");evt.stop();returntrue;}caseEvent.KEY_BACKSPACE:{//Backspacedeletescurrentselectionorprevcharacterif(this.hasNullSelection())this.selectionRange[0]=Math.max(-1,this.selectionRange[0]-1);this.replaceSelectionfromKeyboard("");if(this.charsTyped.length>0)this.charsTyped=this.charsTyped.substring(0,this.charsTyped.length-1);evt.stop();//donotuseforbrowsernavigationreturntrue;}caseEvent.KEY_DELETE:{//Deletedeletescurrentselectionorcurrentcharacterif(this.hasNullSelection())this.selectionRange[1]=Math.min(this.textString.length,this.selectionRange[1]+1);this.replaceSelectionfromKeyboard("");if(this.charsTyped.length>0)this.charsTyped=this.charsTyped.substring(0,this.charsTyped.length-1);evt.stop();//donotuseforbrowsernavigationreturntrue;}caseEvent.KEY_RETURN:{this.replaceSelectionfromKeyboard("\n");evt.stop();returntrue;}caseEvent.KEY_ESC:{this.relinquishKeyboardFocus(this.world().firstHand());returntrue;}}if(ClipboardHack.tryClipboardAction(evt,this)){returntrue;}if((!UserAgent.isWindows&&evt.isMetaDown())||(UserAgent.isWindows&&evt.isCtrlDown())){if(this.processCommandKeys(evt)){evt.stop();returntrue;}}returnfalse},onKeyPress:function(proceed,evt){//console.log("onKeyPress"+evt);if(!this.acceptInput)returntrue;if(!evt.isMetaDown()){this.replaceSelectionfromKeyboard(evt.getKeyChar());evt.stop();//donereturntrue;}returnfalse;},processCommandKeys:function(proceed,evt){console.log("processcommandkey"+evt)returnproceed(evt)},processCommandKeys:function(proceed,evt){//:Boolean(wasthecommandprocessed?)varkey=evt.getKeyChar();//console.log('command'+key);//ARRGHFIXMEif(key=='I'&&evt.isShiftDown()){this.doInspect();returntrue;//Inspect};if(key)key=key.toLowerCase();switch(key){case"a":{this.doSelectAll(true);returntrue;}//SelectAllcase"x":{this.doCut();returntrue;}//Cutcase"c":{this.doCopy();returntrue;}//Copycase"v":{this.doPaste();returntrue;}//Pastecase"m":{this.doMore();returntrue;}//More(repeatreplacement)case"e":{this.doExchange();returntrue;}//Exchangecase"f":{this.doFind();returntrue;}//Findcase"g":{this.doFindNext();returntrue;}//FindaGaincase"w":{this.doSearch();returntrue;}//Where(searchinsystemsourcecode)case"d":{this.doDoit();returntrue;}//Doitcase"p":{this.doPrintit();returntrue;}//Printitcase"s":{this.doSave();returntrue;}//Save//Typefacecase"b":{this.emphasizeBoldItalic({style:'bold'});returntrue;}case"i":{this.emphasizeBoldItalic({style:'italic'});returntrue;}//FontSize//rk:preventscurly/squarebracketsongermankeyboards//case"4":{this.emphasizeSelection({size:(this.fontSize*0.8).roundTo(1)});returntrue;}//case"5":{this.emphasizeSelection({size:(this.fontSize*1).roundTo(1)});returntrue;}//case"6":{this.emphasizeSelection({size:(this.fontSize*1.2).roundTo(1)});returntrue;}//case"7":{this.emphasizeSelection({size:(this.fontSize*1.5).roundTo(1)});returntrue;}//case"8":{this.emphasizeSelection({size:(this.fontSize*2.0).roundTo(1)});returntrue;}//TextAlignmentcase"l":{this.emphasizeSelection({align:'left'});returntrue;}case"r":{this.emphasizeSelection({align:'right'});returntrue;}case"h":{this.emphasizeSelection({align:'center'});returntrue;}case"j":{this.emphasizeSelection({align:'justify'});returntrue;}case"u":{this.linkifySelection(evt);returntrue;}//addlinkattributecase"o":{this.colorSelection(evt);returntrue;}//abitoflocalcolorcase"z":{this.doUndo();returntrue;}//Undo}//FontSizeswitch(evt.getKeyCode()){case189/*alt+'+'*/:{this.emphasizeSelection({size:(this.fontSize*=0.8).roundTo(1)});returntrue;}case187/*alt+'-'*/:{this.emphasizeSelection({size:(this.fontSize*=1.2).roundTo(1)});returntrue;}}//if(evt.type=="KeyPress"){//varbracketIndex=this.locale.charSet.leftBrackets.indexOf(key);//if(bracketIndex>=0){//this.addOrRemoveBrackets(bracketIndex);//returntrue;//}//}returnfalse;},});>reshape\n\t\tClipboardHack.selectPasteBuffer();\n\t\t\n\t\tvar selecting = evt.isShiftDown();\n\t\tvar selectionStopped = !this.hasNullSelection() && !selecting;\n\t\tvar pos = this.getCursorPos(); // is selectionRange[0] or selectionRange[1], depends on selectionPivot\n\t\tvar wordRange = evt.isMetaDown() ? this.locale.selectWord(this.textString, pos) : null;\n\n\t\tvar textMorph = this;\n\t\tvar moveCursor = function(newPos) {\n\t\t\tif (selecting) textMorph.extendSelection(newPos);\n\t\t\telse textMorph.startSelection(newPos);\n\t\t\tevt.stop();\n\t\t\treturn true;\n\t\t};\n\t\t\n\t\tswitch (evt.getKeyCode()) {\n\t\t\tcase Event.KEY_HOME: {\n\t\t\t\t// go to the beginning of the line\n\t\t\t\tvar line = this.lines[this.lineNumberForIndex(pos)] || this.lines.last(); //FIXME\n\t\t\t\treturn moveCursor(line.startIndex);\n\t\t\t}\n\t\t\tcase Event.KEY_END: {\n\t\t\t\t// go to the end of the line\n\t\t\t\tvar line = this.lines[this.lineNumberForIndex(pos)] || this.lines.last(); //FIXME\n\t\t\t\tvar idx = line === this.lines.last() ? line.getStopIndex() + 1 : line.getStopIndex(); // FIXME!!!\n\t\t\t\treturn moveCursor(idx);\n\t\t\t}\n\t\t\tcase Event.KEY_PAGEUP: {\n\t\t\t\t// go to start\n\t\t\t\treturn moveCursor(0);\n\t\t\t}\n\t\t\tcase Event.KEY_PAGEDOWN: {\n\t\t\t\t// go to start\n\t\t\t\treturn moveCursor(this.textString.length);\n\t\t\t}\n\t\t\tcase Event.KEY_LEFT: {\n\t\t\t\tif (selectionStopped) // if a selection exists but but selecting off -> jump to the beginning of the selection\n\t\t\t\t\treturn moveCursor(this.selectionRange[0]);\n\t\t\t\tvar newPos = evt.isMetaDown() && wordRange[0] != pos ? wordRange[0] : pos-1;\n\t\t\t\tnewPos = Math.max(newPos, 0);\n\t\t\t\treturn moveCursor(newPos);\n\t\t\t} \n\t\t\tcase Event.KEY_RIGHT: {\n\t\t\t\tif (selectionStopped) // if a selection exists but selecting off -> jump to the end of the selection\n\t\t\t\t\treturn moveCursor(this.selectionRange[1]+1);\n\t\t\t\tnewPos = evt.isMetaDown() && wordRange[1]+1 != pos ? wordRange[1]+1 : pos + 1;\n\t\t\t\tnewPos = Math.min(this.textString.length, newPos);\n\t\t\t\treturn moveCursor(newPos);\n\t\t\t}\n\t\t\tcase Event.KEY_UP: {\n\t\t\t\tvar lineNo = this.lineNumberForIndex(Math.min(pos, this.textString.length-1));\n\t\t\t\tif (lineNo <= 0) { // cannot move up\n\t\t\t\t\tevt.stop();\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tvar line = this.lines[lineNo];\n\t\t\t\tvar lineIndex = pos - line.startIndex;\n\t\t\t\tvar newLine = this.lines[lineNo - 1];\n\t\t\t\tvar newPos = Math.min(newLine.startIndex + lineIndex, newLine.getStopIndex());\n\t\t\t\treturn moveCursor(newPos);\n\t\t\t}\n\t\t\tcase Event.KEY_DOWN: {\n\t\t\t\tvar lineNo = this.lineNumberForIndex(pos);\n\t\t\t\tif (lineNo >= this.lines.length - 1) { // cannot move down\n\t\t\t\t\tevt.stop();\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tvar line = this.lines[lineNo];\n\t\t\t\tif (!line) {\n\t\t\t\t\t\tconsole.log('TextMorph finds no line ???');\n\t\t\t\t\t\tevt.stop();\n\t\t\t\t\t\treturn true\n\t\t\t\t}\n\t\t\t\tvar lineIndex = pos\t - line.startIndex;\n\t\t\t\tvar newLine = this.lines[lineNo + 1];\n\t\t\t\tvar newPos = Math.min(newLine.startIndex + lineIndex, newLine.getStopIndex());\n\t\t\t\treturn moveCursor(newPos);\n\t\t\t}\n\t\t\tcase Event.KEY_TAB: {\n\t\t\t\tthis.replaceSelectionfromKeyboard(\"\\t\");\n\t\t\t\tevt.stop();\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase Event.KEY_BACKSPACE: {\n\t\t\t\t// Backspace deletes current selection or prev character\n\t\t\t\t\tif (this.hasNullSelection()) this.selectionRange[0] = Math.max(-1, this.selectionRange[0]-1);\n\t\t\t\t\tthis.replaceSelectionfromKeyboard(\"\");\n\t\t\t\tif (this.charsTyped.length > 0) this.charsTyped = this.charsTyped.substring(0, this.charsTyped.length-1); \n\t\t\t\t\tevt.stop(); // do not use for browser navigation\n\t\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase Event.KEY_DELETE: {\t// Delete deletes current selection or current character\n\t\t\t\tif (this.hasNullSelection()) this.selectionRange[1] = Math.min(this.textString.length, this.selectionRange[1]+1);\n\t\t\t\t\tthis.replaceSelectionfromKeyboard(\"\");\n\t\t\t\tif (this.charsTyped.length > 0) this.charsTyped = this.charsTyped.substring(0, this.charsTyped.length-1); \n\t\t\t\tevt.stop(); // do not use for browser navigation\n\t\t\t\treturn true;\n\t\t\t}\t\t\t\n\t\t\tcase Event.KEY_RETURN: {\n\t\t\t\tthis.replaceSelectionfromKeyboard(\"\\n\");\n\t\t\t\tevt.stop();\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\tcase Event.KEY_ESC: {\n\t\t\t\tthis.relinquishKeyboardFocus(this.world().firstHand());\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tif (ClipboardHack.tryClipboardAction(evt, this)) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( (!UserAgent.isWindows && evt.isMetaDown()) || (UserAgent.isWindows && evt.isCtrlDown()) ) {\n\t\t\tif (this.processCommandKeys(evt)) {\n\t\t\t\tevt.stop();\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t\t\n\t},\n\t \n\tonKeyPress: function(proceed, evt) {\n\n\t\t// console.log(\"onKeyPress \" + evt);\n\t\tif (!this.acceptInput)\n\t\t\treturn true;\n\t\t\t\t\n\t\tif (!evt.isMetaDown()) {\n\t\t\tthis.replaceSelectionfromKeyboard(evt.getKeyChar()); \n\t\t\tevt.stop(); // done\n\t\t\treturn true;\n\t\t}\n\t\t\n\t\treturn false;\n\t},\n\t\r\tprocessCommandKeys: function(proceed, evt) {\r\t\tconsole.log(\"process command key \" + evt)\n\t\treturn proceed(evt)\r\t},\r\n\tprocessCommandKeys: function(proceed, evt) {\t //: Boolean (was the command processed?)\n\t\tvar key = evt.getKeyChar();\n\t\t// console.log('command ' + key);\n\n\t\t// ARRGH FIXME\n\t\tif (key == 'I' && evt.isShiftDown()) {\n\t\t\tthis.doInspect(); return true; // Inspect\n\t\t};\n\n\t\tif (key) key = key.toLowerCase();\n\t\tswitch (key) {\n\t\t\tcase \"a\": { this.doSelectAll(true); return true; } // SelectAll\n\t\t\tcase \"x\": { this.doCut(); return true; } // Cut\n\t\t\tcase \"c\": { this.doCopy(); return true; } // Copy\n\t\t\tcase \"v\": { this.doPaste(); return true; } // Paste\n\t\t\tcase \"m\": { this.doMore(); return true; } // More (repeat replacement)\n\t\t\tcase \"e\": { this.doExchange(); return true; } // Exchange\n\t\t\tcase \"f\": { this.doFind(); return true; } // Find\n\t\t\tcase \"g\": { this.doFindNext(); return true; } // Find aGain\n\t\t\tcase \"w\": { this.doSearch(); return true; } // Where (search in system source code)\n\t\t\tcase \"d\": { this.doDoit(); return true; } // Doit\n\t\t\tcase \"p\": { this.doPrintit(); return true; } // Printit\n\t\t\tcase \"s\": { this.doSave(); return true; } // Save\n\n\t\t\t// Typeface\n\t\t\tcase \"b\": { this.emphasizeBoldItalic({style: 'bold'}); return true; }\n\t\t\tcase \"i\": { this.emphasizeBoldItalic({style: 'italic'}); return true; }\n\n\t\t\t// Font Size\n\t\t\t// rk: prevents curly/square brackets on german keyboards\n\t\t\t// case \"4\": { this.emphasizeSelection({size: (this.fontSize*0.8).roundTo(1)}); return true; }\n\t\t\t// case \"5\": { this.emphasizeSelection({size: (this.fontSize*1).roundTo(1)}); return true; }\n\t\t\t// case \"6\": { this.emphasizeSelection({size: (this.fontSize*1.2).roundTo(1)}); return true; }\n\t\t\t// case \"7\": { this.emphasizeSelection({size: (this.fontSize*1.5).roundTo(1)}); return true; }\n\t\t\t// case \"8\": { this.emphasizeSelection({size: (this.fontSize*2.0).roundTo(1)}); return true; }\n\n\t\t\t// Text Alignment\n\t\t\tcase \"l\": { this.emphasizeSelection({align: 'left'}); return true; }\n\t\t\tcase \"r\": { this.emphasizeSelection({align: 'right'}); return true; }\n\t\t\tcase \"h\": { this.emphasizeSelection({align: 'center'}); return true; }\n\t\t\tcase \"j\": { this.emphasizeSelection({align: 'justify'}); return true; }\n\n\t\t\tcase \"u\": { this.linkifySelection(evt); return true; }\t// add link attribute\n\t\t\tcase \"o\": { this.colorSelection(evt); return true; } // a bit of local color\n\n\t\t\tcase \"z\": { this.doUndo(); return true; } // Undo\n\t\t}\n\n\t\t// Font Size\n\t\tswitch(evt.getKeyCode()) {\n\t\t\tcase 189/*alt+'+'*/: { this.emphasizeSelection({size: (this.fontSize*=0.8).roundTo(1)}); return true; }\n\t\t\tcase 187/*alt+'-'*/: { this.emphasizeSelection({size: (this.fontSize*=1.2).roundTo(1)}); return true; }\n\t\t}\n\n\t\t//if (evt.type == \"KeyPress\") {\n\t\t// var bracketIndex = this.locale.charSet.leftBrackets.indexOf(key);\n\n\t\t// if (bracketIndex >= 0) {\n\t\t//\tthis.addOrRemoveBrackets(bracketIndex); \n\t\t//\treturn true;\n\t\t// } \n\t\t//}\n\t\treturn false;\n\t},\n\n\n}); \n\n\r\r"]]>1truetruefalsetruetruetruefalse
false1truefalsenulltruetruefalse
nullfalsetruenullfalse
falsenullfalse
false
false
falsenullfalsefalsenullnullnullnullfalse
null77