Skip to content

Commit

Permalink
Added new vim_command mode. Now, while in command mode, websites can'…
Browse files Browse the repository at this point in the history
…t grab carriage returns and break ex commands. Also added a better shell escape function for ex commands.
  • Loading branch information
ardagnir committed Apr 20, 2014
1 parent 39e22f3 commit 692dcb5
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 21 deletions.
9 changes: 8 additions & 1 deletion plugin/pterosaur.vim
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,17 @@ function! s:WriteMetaFile(fileName, checkInsert)
endif
endfunction

function s:BetterShellEscape(text)
let returnVal = shellescape(a:text, 1)
let returnVal = substitute(returnVal, '\\%', '%', 'g')
let returnVal = substitute(returnVal, '\\#', '#', 'g')
return returnVal
endfunction

function! CheckConsole()
if mode()=="c"
call system('echo c > '.s:metaFile)
call system('echo '.shellescape(getcmdtype().getcmdline(), 1).' >> '.s:metaFile)
call system('echo '.s:BetterShellEscape(getcmdtype().getcmdline()).' >> '.s:metaFile)
if s:fromCommand == 0
ElGroup pterosaur
ElSetting timer 2
Expand Down
77 changes: 57 additions & 20 deletions pterosaur.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function update(){
if (pterosaurCleanupCheck !== options["fullvim"])
cleanupPterosaur();

if (!options["fullvim"] || (dactyl.focusedElement && dactyl.focusedElement.type === "password") || modes.main !== modes.INSERT && modes.main !== modes.AUTOCOMPLETE && modes.main !== modes.VIM_NORMAL) {
if (!options["fullvim"] || (dactyl.focusedElement && dactyl.focusedElement.type === "password") || modes.main !== modes.INSERT && modes.main !== modes.AUTOCOMPLETE && modes.main !== modes.VIM_NORMAL && modes.main !== modes.VIM_COMMAND) {
if(pterFocused && modes.main !== modes.EX) {
cleanupForTextbox();
pterFocused = null
Expand All @@ -78,6 +78,32 @@ function update(){

let val = tmpfile.read();

let metadata = metaTmpfile.read().split('\n');
vimMode = metadata[0];

if (vimMode === "c") {
if ( modes.main !== modes.VIM_COMMAND)
{
modes.push(modes.VIM_COMMAND);
}
if (metadata[1] !=="" && metadata[1] !== lastVimCommand)
{
lastVimCommand = metadata[1]
dactyl.echo("VIM COMMAND " + metadata[1], commandline.FORCE_SINGLELINE);
}
}
else{
if (modes.main === modes.VIM_COMMAND)
{
modes.pop();
}
if (lastVimCommand)
{
dactyl.echo("")
lastVimCommand=""
}
}

let messages = messageTmpfile.read();
if (messages && messages!=="\n")
{
Expand All @@ -90,8 +116,7 @@ function update(){
//We've clearing the entered command. Don't need/want to clear it later and lose our message.
lastVimCommand=""
}
let metadata = metaTmpfile.read().split('\n');
vimMode = metadata[0];

if (vimMode === "e")
dactyl.echo("ERROR: "+metadata[1])
else if (vimMode === "n" && modes.main === modes.INSERT)
Expand All @@ -103,18 +128,6 @@ function update(){
else if (vimMode === "i" && modes.main === modes.VIM_NORMAL)
modes.pop();

if (vimMode === "c") {
if(metadata[1] !=="" && metadata[1] != lastVimCommand)
{
lastVimCommand = metadata[1]
dactyl.echo("VIM COMMAND " + metadata[1], commandline.FORCE_SINGLELINE);
}
}
else if(lastVimCommand) {
dactyl.echo("")
lastVimCommand=""
}

if (textBox) {
if (savedCursorStart!=null && textBox.selectionStart != savedCursorStart || savedCursorEnd!=null && textBox.selectionEnd != savedCursorEnd ) {
pterFocused = null;
Expand Down Expand Up @@ -255,8 +268,6 @@ modes.INSERT.params.onKeyPress = function(eventList) {
io.system("printf '\\b' > /tmp/pterosaur_fifo");
else if (inputChar==="<Return>") {
io.system("printf '\\r' > /tmp/pterosaur_fifo");
if (vimMode !== "c")
return PASS;
}
else if (inputChar==="<Tab>")
return PASS;
Expand Down Expand Up @@ -325,13 +336,20 @@ modes.addMode("VIM_NORMAL", {
char: "N",
desription: "Vim normal mode",
bases: [modes.INSERT]
})
});


modes.addMode("VIM_COMMAND", {
char: "e",
desription: "Vim normal mode",
bases: [modes.VIM_NORMAL]
});

//TODO: Fix these when fullvim is not set
mappings.builtin.add(
[modes.INSERT],
["<ESC>"],
["Override websites' carriage return behavior"],
["Send escape key"],
function(){
io.system("printf '\\e' > /tmp/pterosaur_fifo");
},
Expand All @@ -340,12 +358,21 @@ mappings.builtin.add(
mappings.builtin.add(
[modes.VIM_NORMAL],
["<ESC>"],
["Override websites' carriage return behavior"],
["Leave textfield"],
function(){
modes.reset()
},
{});

mappings.builtin.add(
[modes.VIM_COMMAND],
["<ESC>"],
["Send escape key"],
function(){
io.system("printf '\\e' > /tmp/pterosaur_fifo");
},
{});

mappings.builtin.add(
[modes.INSERT, modes.VIM_NORMAL],
["<C-r>"],
Expand All @@ -355,6 +382,16 @@ mappings.builtin.add(
},
{noTransaction: true});

mappings.builtin.add(
[modes.VIM_COMMAND],
["<Return>"],
["Override websites' carriage return behavior when in command mode"],
function(){
io.system('printf "\\r" > /tmp/pterosaur_fifo');
},
{});


commands.add(["vim[do]"],
"Send command to vim",
function (args) {
Expand Down

0 comments on commit 692dcb5

Please sign in to comment.