Skip to content

Commit

Permalink
Open shifted hints in new tab
Browse files Browse the repository at this point in the history
Typing d shift+a will open link DA in a new tab, even if hints
mode was invoked using f and not shift-f. Closes #63.
  • Loading branch information
gggritso committed Aug 2, 2017
1 parent 200131a commit 193c445
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/prototypeExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@
return this.split( '' ).reverse().join( '' );
};

String.prototype.isCapital = function() {
return this.toUpperCase() === this;
}


})();
29 changes: 20 additions & 9 deletions src/vimmy2.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
var
MODE = 'command',
FORCE_NEW_TAB = false,
FORCE_NEW_TAB_EXCEPTION = false,
ROTATE_HINTS = true,

SCROLL_IS_LOCKED = false,
Expand Down Expand Up @@ -255,10 +256,18 @@
return;
}

if ( key.toUpperCase().isIn( CHARACTERS ) ) {
var letter;

if ( key.startsWith( 'shift-' ) ) {
letter = key.slice( 6 ).toUpperCase();
} else {
letter = key;
}

if ( letter.toUpperCase().isIn( CHARACTERS ) ) {
swallowEvent( event );

TYPED_HINT_CHARACTERS.push( key );
TYPED_HINT_CHARACTERS.push( letter );
filterHints( TYPED_HINT_CHARACTERS );
}

Expand Down Expand Up @@ -454,6 +463,8 @@
if ( activeHints.length > 1 ) return;
activeHint = activeHints[ 0 ];

if ( characters.slice( -1 )[ 0 ].isCapital() ) FORCE_NEW_TAB_EXCEPTION = true;

if ( activeHint.text === prefix ) {
activateElement( activeHint.$element );
highlightHint( activeHint.$hint );
Expand Down Expand Up @@ -481,18 +492,17 @@
activator( $element );
}, 0 );

if ( !FORCE_NEW_TAB ) {
if ( FORCE_NEW_TAB || FORCE_NEW_TAB_EXCEPTION ) {
window.setTimeout( function() {

hideHints();
MODE = 'command';
TYPED_HINT_CHARACTERS = [];
filterHints( TYPED_HINT_CHARACTERS );
}, 150 );
} else {

window.setTimeout( function() {

TYPED_HINT_CHARACTERS = [];
filterHints( TYPED_HINT_CHARACTERS );
hideHints();
MODE = 'command';
}, 150 );
}

Expand Down Expand Up @@ -540,13 +550,14 @@
target = $anchor.getAttribute( 'target' ),
url = makeAbsoluteUrl( href );

if ( FORCE_NEW_TAB ) {
if ( FORCE_NEW_TAB || FORCE_NEW_TAB_EXCEPTION ) {

safari.self.tab.dispatchMessage( 'newtab', {
url: url,
visibility: 'background',
});

FORCE_NEW_TAB_EXCEPTION = false;
} else if ( target === '_blank' ) {

safari.self.tab.dispatchMessage( 'newtab', {
Expand Down

0 comments on commit 193c445

Please sign in to comment.