nano improved

This commit is contained in:
BlackLight 2011-01-03 22:16:19 +01:00
parent 140b4a6099
commit 8ebfc30165
2 changed files with 88 additions and 21 deletions

View File

@ -70,8 +70,9 @@
shell.editorkeypressed = this.editorkeypressed;
shell.confirmkey = this.confirmkey;
shell.bufferSave = this.bufferSave;
shell.firstKey = true; // Set when no key has been pressed yet
shell.default_editor_status = "[<b>^X</b> Exit] [<b>^O</b> WriteOut] [<b>^W</b> Where Is]";
shell.default_editor_status = "[<b>^X</b> Exit] [<b>^O</b> WriteOut] [<b>^F</b> Where Is]";
if ( shell.perms )
{
@ -107,7 +108,6 @@
editor.setAttribute ( 'class', 'editor_window' );
editor.setAttribute ( 'id', 'editor_window' );
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' );
editor.innerHTML = '';
has_content = false;
@ -154,26 +154,16 @@
{
var evt = ( window.event ) ? window.event : e;
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
key = String.fromCharCode ( key );
if ( !shell.file_changed )
if ( shell.firstKey && key == 13 )
{
if ( shell.originalContent != shell.editor_window.value )
{
if ( shell.perms )
{
if ( shell.perms.write == false )
{
shell.default_editor_status += ' [read-only]';
shell.editor_status.innerHTML += ' [read-only]';
}
}
shell.editor_status.innerHTML += ' [modified]';
shell.file_changed = true;
}
evt.preventDefault();
shell.firstKey = false;
return false;
}
key = String.fromCharCode ( key );
if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
{
evt.preventDefault();
@ -208,6 +198,8 @@
shell.auto_prompt_refresh = true;
shell.refreshPrompt ( true );
}
return false;
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
evt.preventDefault();
@ -230,14 +222,87 @@
shell.editor_status.innerHTML = shell.default_editor_status;
}
}
return false;
} else if (( key == 'f' || key == 'F' ) && evt.ctrlKey ) {
evt.preventDefault();
shell.editor_status.innerHTML = 'Text or regex to search: ' +
'<input type="text" class="editor_status_input" id="editor_status_input" '+
'onkeydown="shell.confirmkey ( event, ' + "'find'" + ' )"/>';
document.getElementById ( 'editor_status_input' ).focus();
return false;
}
if ( !shell.file_changed )
{
if ( shell.originalContent != shell.editor_window.value )
{
if ( shell.perms )
{
if ( shell.perms.write == false )
{
shell.default_editor_status += ' [read-only]';
shell.editor_status.innerHTML += ' [read-only]';
}
}
shell.editor_status.innerHTML += ' [modified]';
shell.file_changed = true;
}
}
},
"confirmkey" : function ( e )
"confirmkey" : function ( e, arg )
{
var can_write = false;
var evt = ( window.event ) ? window.event : e;
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
if ( arg )
{
if ( arg == "find" )
{
var input = document.getElementById ( 'editor_status_input' );
var idx = -1;
if ( key == 13 )
{
shell.firstKey = true;
if ( input.value.length > 0 )
{
var matches = shell.editor_window.value.match ( new RegExp ( input.value ));
if ( matches )
{
idx = shell.editor_window.value.indexOf ( matches[0] );
}
}
shell.editor_status.innerHTML = shell.default_editor_status;
shell.editor_window.focus();
if ( idx > -1 )
{
if ( shell.editor_window.setSelectionRange )
{
shell.editor_window.setSelectionRange ( idx, idx + input.value.length );
}
} else {
shell.editor_status.innerHTML = 'No matches found';
setTimeout ( 'shell.editor_status.innerHTML = shell.default_editor_status', 1500 );
}
return false;
}
}
return false;
}
key = String.fromCharCode ( key );
if ( shell.perms )
@ -266,6 +331,7 @@
case 'n':
case 'N':
evt.preventDefault();
shell.firstKey = true;
shell.auto_prompt_focus = true;
shell.auto_prompt_refresh = true;
shell.refreshPrompt ( true );
@ -289,6 +355,7 @@
case 'y':
case 'Y':
evt.preventDefault();
shell.firstKey = true;
shell.auto_prompt_focus = true;
shell.auto_prompt_refresh = true;
shell.refreshPrompt ( true );
@ -321,7 +388,7 @@
if ( http.responseText.length > 0 )
{
shell.editor_status.innerHTML = http.responseText;
setTimeout ( 'shell.editor_status.innerHTML = shell.default_editor_status', 5000 );
setTimeout ( 'shell.editor_status.innerHTML = shell.default_editor_status', 1500 );
var files_config = window.location.href;
files_config = files_config.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/files.php' );

View File

@ -32,7 +32,7 @@ $files_json = <<<JSON
, {"path": "/irc", "type": "file", "content": "IRC channel at #thegame@irc.randomstuff.com"}
, {"path": "/root", "type": "directory", "can_read": "root", "can_write": "root"}
, {"path": "/home/blacklight", "type": "directory", "owner": "blacklight", "can_read": "blacklight", "can_write": "blacklight"}
, {"path": "/home/blacklight/lol", "type": "file", "owner": "blacklight", "can_read": "@all", "can_write": "blacklight", "content": "this is a test<br/>lol lol asd 'lol' &lt;asd&gt; 'asd'"}
, {"path": "/home/blacklight/lol", "type": "file", "owner": "blacklight", "can_read": "@all", "can_write": "blacklight", "content": "#include &lt;stdio.h&gt;<br/><br/>int main () {<br/> printf ( 'loln' );<br/>}"}
]
JSON;