nano improved
This commit is contained in:
parent
140b4a6099
commit
8ebfc30165
2 changed files with 88 additions and 21 deletions
|
@ -70,8 +70,9 @@
|
||||||
shell.editorkeypressed = this.editorkeypressed;
|
shell.editorkeypressed = this.editorkeypressed;
|
||||||
shell.confirmkey = this.confirmkey;
|
shell.confirmkey = this.confirmkey;
|
||||||
shell.bufferSave = this.bufferSave;
|
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 )
|
if ( shell.perms )
|
||||||
{
|
{
|
||||||
|
@ -107,7 +108,6 @@
|
||||||
editor.setAttribute ( 'class', 'editor_window' );
|
editor.setAttribute ( 'class', 'editor_window' );
|
||||||
editor.setAttribute ( 'id', 'editor_window' );
|
editor.setAttribute ( 'id', 'editor_window' );
|
||||||
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' );
|
editor.setAttribute ( 'onkeypress', 'shell.editorkeypressed ( event )' );
|
||||||
editor.innerHTML = '';
|
|
||||||
|
|
||||||
has_content = false;
|
has_content = false;
|
||||||
|
|
||||||
|
@ -154,26 +154,16 @@
|
||||||
{
|
{
|
||||||
var evt = ( window.event ) ? window.event : e;
|
var evt = ( window.event ) ? window.event : e;
|
||||||
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
||||||
|
|
||||||
|
if ( shell.firstKey && key == 13 )
|
||||||
|
{
|
||||||
|
evt.preventDefault();
|
||||||
|
shell.firstKey = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
key = String.fromCharCode ( key );
|
key = String.fromCharCode ( key );
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
|
if (( key == 'x' || key == 'X' ) && evt.ctrlKey )
|
||||||
{
|
{
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
@ -208,6 +198,8 @@
|
||||||
shell.auto_prompt_refresh = true;
|
shell.auto_prompt_refresh = true;
|
||||||
shell.refreshPrompt ( true );
|
shell.refreshPrompt ( true );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
|
} else if (( key == 'o' || key == 'O' ) && evt.ctrlKey ) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
|
||||||
|
@ -230,14 +222,87 @@
|
||||||
shell.editor_status.innerHTML = shell.default_editor_status;
|
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 can_write = false;
|
||||||
var evt = ( window.event ) ? window.event : e;
|
var evt = ( window.event ) ? window.event : e;
|
||||||
var key = ( evt.charCode ) ? evt.charCode : evt.keyCode;
|
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 );
|
key = String.fromCharCode ( key );
|
||||||
|
|
||||||
if ( shell.perms )
|
if ( shell.perms )
|
||||||
|
@ -266,6 +331,7 @@
|
||||||
case 'n':
|
case 'n':
|
||||||
case 'N':
|
case 'N':
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
shell.firstKey = true;
|
||||||
shell.auto_prompt_focus = true;
|
shell.auto_prompt_focus = true;
|
||||||
shell.auto_prompt_refresh = true;
|
shell.auto_prompt_refresh = true;
|
||||||
shell.refreshPrompt ( true );
|
shell.refreshPrompt ( true );
|
||||||
|
@ -289,6 +355,7 @@
|
||||||
case 'y':
|
case 'y':
|
||||||
case 'Y':
|
case 'Y':
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
|
shell.firstKey = true;
|
||||||
shell.auto_prompt_focus = true;
|
shell.auto_prompt_focus = true;
|
||||||
shell.auto_prompt_refresh = true;
|
shell.auto_prompt_refresh = true;
|
||||||
shell.refreshPrompt ( true );
|
shell.refreshPrompt ( true );
|
||||||
|
@ -321,7 +388,7 @@
|
||||||
if ( http.responseText.length > 0 )
|
if ( http.responseText.length > 0 )
|
||||||
{
|
{
|
||||||
shell.editor_status.innerHTML = http.responseText;
|
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;
|
var files_config = window.location.href;
|
||||||
files_config = files_config.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/files.php' );
|
files_config = files_config.replace ( /\/([a-zA-Z\.]+)$/, '/modules/users/files.php' );
|
||||||
|
|
|
@ -32,7 +32,7 @@ $files_json = <<<JSON
|
||||||
, {"path": "/irc", "type": "file", "content": "IRC channel at #thegame@irc.randomstuff.com"}
|
, {"path": "/irc", "type": "file", "content": "IRC channel at #thegame@irc.randomstuff.com"}
|
||||||
, {"path": "/root", "type": "directory", "can_read": "root", "can_write": "root"}
|
, {"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", "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' <asd> 'asd'"}
|
, {"path": "/home/blacklight/lol", "type": "file", "owner": "blacklight", "can_read": "@all", "can_write": "blacklight", "content": "#include <stdio.h><br/><br/>int main () {<br/> printf ( 'loln' );<br/>}"}
|
||||||
]
|
]
|
||||||
|
|
||||||
JSON;
|
JSON;
|
||||||
|
|
Loading…
Reference in a new issue