Improving nano editor (thanks to tragic0mic)
This commit is contained in:
parent
fbb1d6ff5b
commit
1f75240b42
1 changed files with 72 additions and 20 deletions
|
@ -68,9 +68,11 @@
|
|||
|
||||
shell.fname = arg;
|
||||
shell.editorkeypressed = this.editorkeypressed;
|
||||
shell.editorpaste = this.editorpaste;
|
||||
shell.editorclick = this.editorclick;
|
||||
shell.confirmkey = this.confirmkey;
|
||||
shell.bufferSave = this.bufferSave;
|
||||
shell.firstKey = true; // Set when no key has been pressed yet
|
||||
shell.firstKey = 1; // Set when no key has been pressed yet
|
||||
|
||||
shell.default_editor_status = "[<b>^X</b> Exit] [<b>^O</b> WriteOut] [<b>^F</b> Where Is]";
|
||||
|
||||
|
@ -105,9 +107,13 @@
|
|||
shell.editor_head = document.getElementById ( 'editor_head' );
|
||||
|
||||
var editor = document.createElement ( 'textarea' );
|
||||
|
||||
editor.setAttribute ( 'class', 'editor_window' );
|
||||
editor.setAttribute ( 'id', 'editor_window' );
|
||||
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' );
|
||||
// editor.setAttribute ( 'onmousedown', 'shell.editorclick ( event )' ); /* This might be useful someday */
|
||||
editor.setAttribute ( 'onpaste', 'shell.editorpaste ( )' );
|
||||
editor.setAttribute ( 'oncut', 'shell.editorpaste( )' );
|
||||
|
||||
has_content = false;
|
||||
|
||||
|
@ -117,7 +123,7 @@
|
|||
{
|
||||
if ( file.content.length > 0 )
|
||||
{
|
||||
var content = file.content.replace ( /<br\/?>/g, "\n" );
|
||||
var content = file.content.replace ( /(<br ?\/?>)/g, "\n" );
|
||||
content = content.replace ( /</g, '<' );
|
||||
content = content.replace ( />/g, '>' );
|
||||
editor.value = content;
|
||||
|
@ -146,29 +152,44 @@
|
|||
|
||||
container.appendChild ( status );
|
||||
shell.editor_status = document.getElementById ( 'editor_status' );
|
||||
shell.hitCount = 0;
|
||||
|
||||
return '';
|
||||
},
|
||||
|
||||
"editorkeypressed" : function ( e )
|
||||
{
|
||||
shell.hitCount++;
|
||||
var evt = ( window.event ) ? window.event : e;
|
||||
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
||||
|
||||
if ( shell.firstKey && key == 13 )
|
||||
if ( shell.firstKey == 1 && key == 13 )
|
||||
{
|
||||
evt.preventDefault();
|
||||
shell.firstKey = false;
|
||||
shell.firstKey = -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(shell.firstKey == -1)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
if(shell.perms.write == false)
|
||||
shell.editor_status.innerHTML += " [read-only]";
|
||||
shell.editor_status.innerHTML += " [modified]";
|
||||
shell.firstKey = 0;
|
||||
shell.editor_window.value = shell.editor_window.value.replace(/(\n|\r)+$/, '');
|
||||
}
|
||||
|
||||
key = String.fromCharCode ( key );
|
||||
|
||||
if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
|
||||
{
|
||||
evt.preventDefault();
|
||||
|
||||
if ( shell.file_changed )
|
||||
if(shell.originalContent != shell.editor_window.value)
|
||||
shell.file_changed = true;
|
||||
|
||||
if ( shell.file_changed && shell.hitCount > 2)
|
||||
{
|
||||
var can_write = false;
|
||||
|
||||
|
@ -203,6 +224,9 @@
|
|||
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
|
||||
evt.preventDefault();
|
||||
|
||||
if( shell.originalContent != shell.editor_window.value )
|
||||
shell.file_changed = true;
|
||||
|
||||
if ( shell.file_changed )
|
||||
{
|
||||
var can_write = false;
|
||||
|
@ -247,11 +271,11 @@
|
|||
shell.editor_status.innerHTML += ' [read-only]';
|
||||
}
|
||||
}
|
||||
|
||||
shell.editor_status.innerHTML += ' [modified]';
|
||||
shell.file_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
"confirmkey" : function ( e, arg )
|
||||
|
@ -397,6 +421,34 @@
|
|||
http.send ( params );
|
||||
shell.originalContent = shell.editor_window.value;
|
||||
shell.file_changed = false;
|
||||
},
|
||||
|
||||
"editorpaste" : function ( )
|
||||
{
|
||||
if(shell.perms)
|
||||
{
|
||||
if(shell.perms.write == true)
|
||||
{
|
||||
if(shell.file_changed == false)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
shell.editor_status.innerHTML += ' [modified]';
|
||||
}
|
||||
}
|
||||
else
|
||||
if(shell.file_changed == false)
|
||||
{
|
||||
shell.file_changed = true;
|
||||
shell.editor_status.innerHTML += ' [read-only] [modified]';
|
||||
}
|
||||
}
|
||||
return;
|
||||
},
|
||||
|
||||
"editorclick": function ( e )
|
||||
{
|
||||
if (e.button == 2); /* Do something with the right button */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue