1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-30 21:22:28 +01:00

First commit of caret mode, many things work, some bugs of course, not sure if we can fix them since

we heavily rely on the firefox interface for it.
This commit is contained in:
Martin Stubenschrott
2007-09-06 16:10:25 +00:00
parent 5f6958521e
commit d9888288f3
3 changed files with 214 additions and 49 deletions

View File

@@ -386,6 +386,10 @@ function Events() //{{{
if (vimperator.hasMode(vimperator.modes.CARET))
Options.setFirefoxPref("accessibility.browsewithcaret", false);
// clear any selection made
var selection = window.content.getSelection();
selection.collapseToStart();
vimperator.setMode(vimperator.modes.NORMAL);
vimperator.commandline.clear();
vimperator.hints.disableHahMode();
@@ -431,8 +435,8 @@ function Events() //{{{
elt.value = tempStr1 + tempStr2 + tempStr3;
elt.selectionStart = rangeStart + tempStr2.length;
elt.selectionEnd = elt.selectionStart;
// prevent additional firefox-clipboard pasting
event.preventDefault();
// prevents additional firefox-clipboard pasting
}
}
return false;
@@ -553,63 +557,63 @@ function Events() //{{{
return true;
}
if (vimperator.hasMode(vimperator.modes.NORMAL))
var [mode, extended_mode] = vimperator.getMode();
var count_str = vimperator.input.buffer.match(/^[0-9]*/)[0];
var candidate_command = (vimperator.input.buffer + key).replace(count_str, '');
var map;
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
{
var count_str = vimperator.input.buffer.match(/^[0-9]*/)[0];
var candidate_command = (vimperator.input.buffer + key).replace(count_str, '');
var map;
vimperator.input.buffer += key;
vimperator.statusline.updateInputBuffer(vimperator.input.buffer);
return true;
}
// counts must be at the start of a complete mapping (10j -> go 10 lines down)
if ((vimperator.input.buffer + key).match(/^[1-9][0-9]*$/))
if (vimperator.input.pendingMap)
{
vimperator.input.buffer = "";
if (key != "<Esc>" && key != "<C-[>")
vimperator.input.pendingMap.execute(null, vimperator.input.count, key);
vimperator.input.pendingMap = null;
event.preventDefault();
event.stopPropagation();
}
else if (map = vimperator.mappings.get(mode, candidate_command))
{
vimperator.input.count = parseInt(count_str, 10);
if (isNaN(vimperator.input.count))
vimperator.input.count = -1;
if (map.flags & Mappings.flags.ARGUMENT)
{
vimperator.input.pendingMap = map;
vimperator.input.buffer += key;
vimperator.statusline.updateInputBuffer(vimperator.input.buffer);
return true;
}
if (vimperator.input.pendingMap)
{
vimperator.input.buffer = "";
if (key != "<Esc>" && key != "<C-[>")
vimperator.input.pendingMap.execute(null, vimperator.input.count, key);
vimperator.input.pendingMap = null;
event.preventDefault();
event.stopPropagation();
}
else if (map = vimperator.mappings.get(vimperator.modes.NORMAL, candidate_command))
{
vimperator.input.count = parseInt(count_str, 10);
if (isNaN(vimperator.input.count))
vimperator.input.count = -1;
if (map.flags & Mappings.flags.ARGUMENT)
{
vimperator.input.pendingMap = map;
vimperator.input.buffer += key;
}
else
{
vimperator.input.buffer = "";
map.execute(null, vimperator.input.count);
}
event.preventDefault();
event.stopPropagation();
}
else if (vimperator.mappings.getCandidates(vimperator.modes.NORMAL, candidate_command).length > 0)
{
vimperator.input.buffer += key;
event.preventDefault();
event.stopPropagation();
}
else
{
vimperator.input.buffer = "";
vimperator.input.pendingMap = null;
vimperator.beep();
map.execute(null, vimperator.input.count);
}
event.preventDefault();
event.stopPropagation();
}
else if (vimperator.mappings.getCandidates(mode, candidate_command).length > 0)
{
vimperator.input.buffer += key;
event.preventDefault();
event.stopPropagation();
}
else
{
vimperator.input.buffer = "";
vimperator.input.pendingMap = null;
vimperator.beep();
}
vimperator.statusline.updateInputBuffer(vimperator.input.buffer);
return false;
}

View File

@@ -1208,7 +1208,7 @@ function Mappings() //{{{
always_active: true
}
));
addDefaultMap(new Map(vimperator.modes.HINTS, ["<Esc>"],
addDefaultMap(new Map(vimperator.modes.HINTS, ["<Esc>", "<C-[>", "<C-c>"],
function() { ; },
{
cancel_mode: true,
@@ -1217,6 +1217,166 @@ function Mappings() //{{{
));
//}}}
//}}}
// Caret mode
function getSelectionController()
{
return getBrowser().docShell
.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
.getInterface(Components.interfaces.nsISelectionDisplay)
.QueryInterface(Components.interfaces.nsISelectionController);
}
// prevent beeping on esc, should unify
addDefaultMap(new Map(vimperator.modes.CARET, ["<Esc>", "<C-[>", "<C-c>"],
function()
{
if (!vimperator.hasMode(vimperator.modes.VISUAL))
vimperator.onEscape();
else
{
vimperator.removeMode(null, vimperator.modes.VISUAL);
// clear any selection made
// FIXME: need to make more general to allow caret/visual mode also for text fields
var selection = window.content.getSelection();
selection.collapseToStart();
}
},
{ }
));
addDefaultMap(new Map(vimperator.modes.CARET, ["v"],
function(count)
{
vimperator.addMode(null, vimperator.modes.VISUAL);
},
{
short_help: "Start visual mode",
help: "Must be in caret mode for now, later also for text fields"
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["j", "<Down>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().lineMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["k", "<Up>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().lineMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["h", "<Left>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().characterMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["l", "<Right>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().characterMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["b", "B"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().wordMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["w", "W"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().wordMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["<C-f>", "<PageDown>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().pageMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["<C-b>", "<PageUp>"],
function(count)
{
if (count < 1) count = 1;
while(count--)
getSelectionController().pageMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{
flags: Mappings.flags.COUNT
}
));
addDefaultMap(new Map(vimperator.modes.CARET, ["gg", "<C-Home>"],
function(count)
{
getSelectionController().completeMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{ }
));
addDefaultMap(new Map(vimperator.modes.CARET, ["G", "<C-End>"],
function(count)
{
// no count support for now
getSelectionController().completeMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{ }
));
addDefaultMap(new Map(vimperator.modes.CARET, ["0", "^"],
function(count)
{
getSelectionController().intraLineMove(false, vimperator.hasMode(vimperator.modes.VISUAL));
},
{ }
));
addDefaultMap(new Map(vimperator.modes.CARET, ["$"],
function(count)
{
getSelectionController().intraLineMove(true, vimperator.hasMode(vimperator.modes.VISUAL));
},
{ }
));
} //}}}
// vim: set fdm=marker sw=4 ts=4 et: