Compare commits
3 Commits
e75bcfa478
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4d392962a | ||
|
|
4d5be13b51 | ||
|
|
97ca274070 |
@@ -1,4 +1,4 @@
|
|||||||
// Outcut — Keyboard Navigation & Multi-Select
|
// Outlook Relook — Gmail-Style Keyboard Navigation & Multi-Select
|
||||||
// Adds keyboard focus cursor and multi-select to OWA's message list.
|
// Adds keyboard focus cursor and multi-select to OWA's message list.
|
||||||
// Gated by the keyboardMultiSelect setting.
|
// Gated by the keyboardMultiSelect setting.
|
||||||
//
|
//
|
||||||
@@ -7,53 +7,6 @@
|
|||||||
|
|
||||||
window.OutlookRelook = window.OutlookRelook || {};
|
window.OutlookRelook = window.OutlookRelook || {};
|
||||||
|
|
||||||
// Keyboard shortcut presets
|
|
||||||
var KEY_PRESETS = {
|
|
||||||
gmail: {
|
|
||||||
nextMessage: [{key: 'j'}, {key: 'ArrowDown'}],
|
|
||||||
prevMessage: [{key: 'k'}, {key: 'ArrowUp'}],
|
|
||||||
selectExtendDown: [{key: 'j', shift: true}, {key: 'ArrowDown', shift: true}],
|
|
||||||
selectExtendUp: [{key: 'k', shift: true}, {key: 'ArrowUp', shift: true}],
|
|
||||||
toggleSelect: [{key: 'x'}, {key: ' '}],
|
|
||||||
delete: [{key: '#'}],
|
|
||||||
archive: [{key: 'e'}],
|
|
||||||
readUnread: [{key: 'I', shift: true}, {key: 'U', shift: true}],
|
|
||||||
move: [{key: 'v'}],
|
|
||||||
flag: [{key: 'f'}],
|
|
||||||
pin: [{key: 'p'}],
|
|
||||||
deselect: [{key: 'Escape'}],
|
|
||||||
open: [{key: 'Enter'}, {key: 'o'}],
|
|
||||||
label: 'Gmail-style: j/k nav, x select, # del, e archive'
|
|
||||||
},
|
|
||||||
outlook: {
|
|
||||||
nextMessage: [{key: 'ArrowDown'}, {key: 'j'}],
|
|
||||||
prevMessage: [{key: 'ArrowUp'}, {key: 'k'}],
|
|
||||||
selectExtendDown: [{key: 'ArrowDown', shift: true}],
|
|
||||||
selectExtendUp: [{key: 'ArrowUp', shift: true}],
|
|
||||||
toggleSelect: [{key: ' '}],
|
|
||||||
delete: [{key: 'Delete'}, {key: 'Backspace'}],
|
|
||||||
archive: [{key: 'e'}],
|
|
||||||
readUnread: [{key: 'q'}, {key: 'I', shift: true}],
|
|
||||||
move: [{key: 'v'}],
|
|
||||||
flag: [{key: 'Insert'}, {key: 'f'}],
|
|
||||||
pin: [{key: 'p'}],
|
|
||||||
deselect: [{key: 'Escape'}],
|
|
||||||
open: [{key: 'Enter'}],
|
|
||||||
label: 'Outlook-style: arrows nav, Space select, Del delete'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
function matchesAction(e, actionBindings) {
|
|
||||||
if (!actionBindings) return false;
|
|
||||||
for (var i = 0; i < actionBindings.length; i++) {
|
|
||||||
var b = actionBindings[i];
|
|
||||||
if (e.key === b.key && !!e.shiftKey === !!b.shift && !!e.ctrlKey === !!b.ctrl) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.OutlookRelook.Keyboard = (function () {
|
window.OutlookRelook.Keyboard = (function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -134,6 +87,9 @@ window.OutlookRelook.Keyboard = (function () {
|
|||||||
var idx = findItemById(items, id);
|
var idx = findItemById(items, id);
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
items[idx].classList.add('or-kb-selected');
|
items[idx].classList.add('or-kb-selected');
|
||||||
|
console.log('[Outcut] Applied or-kb-selected to', id.substring(0, 20), 'hasClass:', items[idx].classList.contains('or-kb-selected'));
|
||||||
|
} else {
|
||||||
|
console.log('[Outcut] Could not find item for selected id:', id.substring(0, 20));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -372,6 +328,18 @@ window.OutlookRelook.Keyboard = (function () {
|
|||||||
|
|
||||||
// --- Key handler ---
|
// --- Key handler ---
|
||||||
|
|
||||||
|
// Outlook preset: map Outlook-native keys to the Gmail-style internal keys
|
||||||
|
// used by the switch below. This way the action code stays untouched.
|
||||||
|
function remapForOutlookPreset(key, shift) {
|
||||||
|
// Delete/Backspace → '#' (delete)
|
||||||
|
if (key === 'Delete' || key === 'Backspace') return { key: '#', shift: shift };
|
||||||
|
// q → mark read/unread (Outlook native shortcut for read/unread)
|
||||||
|
if (key === 'q' && !shift) return { key: 'I', shift: true };
|
||||||
|
// Insert → flag
|
||||||
|
if (key === 'Insert') return { key: 'f', shift: shift };
|
||||||
|
return { key: key, shift: shift };
|
||||||
|
}
|
||||||
|
|
||||||
function handleKeydown(e) {
|
function handleKeydown(e) {
|
||||||
if (!currentSettings.keyboardMultiSelect) return;
|
if (!currentSettings.keyboardMultiSelect) return;
|
||||||
if (isComposeOrDialogActive()) return;
|
if (isComposeOrDialogActive()) return;
|
||||||
@@ -379,8 +347,15 @@ window.OutlookRelook.Keyboard = (function () {
|
|||||||
var items = getMessageItems();
|
var items = getMessageItems();
|
||||||
if (items.length === 0) return;
|
if (items.length === 0) return;
|
||||||
|
|
||||||
var presetName = currentSettings.keyboardPreset || 'gmail';
|
var key = e.key;
|
||||||
var preset = KEY_PRESETS[presetName] || KEY_PRESETS.gmail;
|
var shift = e.shiftKey;
|
||||||
|
|
||||||
|
// Apply Outlook preset key remapping if active
|
||||||
|
if (currentSettings.keyboardPreset === 'outlook') {
|
||||||
|
var remapped = remapForOutlookPreset(key, shift);
|
||||||
|
key = remapped.key;
|
||||||
|
shift = remapped.shift;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize focus if not set
|
// Initialize focus if not set
|
||||||
var currentIdx = getFocusedIndex(items);
|
var currentIdx = getFocusedIndex(items);
|
||||||
@@ -403,54 +378,101 @@ window.OutlookRelook.Keyboard = (function () {
|
|||||||
var handled = true;
|
var handled = true;
|
||||||
var targets;
|
var targets;
|
||||||
|
|
||||||
if (matchesAction(e, preset.selectExtendDown)) {
|
switch (key) {
|
||||||
|
case 'j':
|
||||||
|
case 'ArrowDown':
|
||||||
|
if (shift) {
|
||||||
toggleSelect(items, currentIdx);
|
toggleSelect(items, currentIdx);
|
||||||
if (currentIdx < items.length - 1) {
|
if (currentIdx < items.length - 1) {
|
||||||
setFocus(items, currentIdx + 1);
|
setFocus(items, currentIdx + 1);
|
||||||
toggleSelect(items, currentIdx + 1);
|
toggleSelect(items, currentIdx + 1);
|
||||||
}
|
}
|
||||||
} else if (matchesAction(e, preset.selectExtendUp)) {
|
} else {
|
||||||
|
if (currentIdx < items.length - 1) {
|
||||||
|
setFocus(items, currentIdx + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'k':
|
||||||
|
case 'ArrowUp':
|
||||||
|
if (shift) {
|
||||||
toggleSelect(items, currentIdx);
|
toggleSelect(items, currentIdx);
|
||||||
if (currentIdx > 0) {
|
if (currentIdx > 0) {
|
||||||
setFocus(items, currentIdx - 1);
|
setFocus(items, currentIdx - 1);
|
||||||
toggleSelect(items, currentIdx - 1);
|
toggleSelect(items, currentIdx - 1);
|
||||||
}
|
}
|
||||||
} else if (matchesAction(e, preset.nextMessage)) {
|
} else {
|
||||||
if (currentIdx < items.length - 1) setFocus(items, currentIdx + 1);
|
if (currentIdx > 0) {
|
||||||
} else if (matchesAction(e, preset.prevMessage)) {
|
setFocus(items, currentIdx - 1);
|
||||||
if (currentIdx > 0) setFocus(items, currentIdx - 1);
|
}
|
||||||
} else if (matchesAction(e, preset.toggleSelect)) {
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'x':
|
||||||
|
case ' ':
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
toggleSelect(items, currentIdx);
|
toggleSelect(items, currentIdx);
|
||||||
} else if (matchesAction(e, preset.delete)) {
|
break;
|
||||||
|
|
||||||
|
case '#':
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionDelete(targets);
|
actionDelete(targets);
|
||||||
} else if (matchesAction(e, preset.archive)) {
|
break;
|
||||||
|
|
||||||
|
case 'e':
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionArchive(targets);
|
actionArchive(targets);
|
||||||
} else if (matchesAction(e, preset.readUnread)) {
|
break;
|
||||||
|
|
||||||
|
case 'I':
|
||||||
|
case 'U':
|
||||||
|
// Shift+i or Shift+u — OWA uses a single "Read / Unread" toggle
|
||||||
|
if (shift) {
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionMarkReadUnread(targets);
|
actionMarkReadUnread(targets);
|
||||||
} else if (matchesAction(e, preset.move)) {
|
} else {
|
||||||
|
handled = false;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'v':
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionMove(targets);
|
actionMove(targets);
|
||||||
} else if (matchesAction(e, preset.flag)) {
|
break;
|
||||||
|
|
||||||
|
case 'f':
|
||||||
|
// Flag/unflag
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionFlag(targets);
|
actionFlag(targets);
|
||||||
} else if (matchesAction(e, preset.pin)) {
|
break;
|
||||||
|
|
||||||
|
case 'p':
|
||||||
|
// Pin/unpin
|
||||||
targets = getActionTargets(items);
|
targets = getActionTargets(items);
|
||||||
actionPin(targets);
|
actionPin(targets);
|
||||||
} else if (matchesAction(e, preset.deselect)) {
|
break;
|
||||||
|
|
||||||
|
case 'Escape':
|
||||||
clearSelection();
|
clearSelection();
|
||||||
} else if (matchesAction(e, preset.open)) {
|
break;
|
||||||
if (currentIdx >= 0 && currentIdx < items.length) items[currentIdx].click();
|
|
||||||
} else {
|
case 'Enter':
|
||||||
|
case 'o':
|
||||||
|
if (currentIdx >= 0 && currentIdx < items.length) {
|
||||||
|
items[currentIdx].click();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
handled = false;
|
handled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (handled) {
|
if (handled) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
if (e.key !== 'Enter') e.preventDefault();
|
if (key !== 'Enter' && key !== 'o') {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -506,11 +528,9 @@ window.OutlookRelook.Keyboard = (function () {
|
|||||||
function updateSettings(settings) {
|
function updateSettings(settings) {
|
||||||
var wasEnabled = currentSettings.keyboardMultiSelect;
|
var wasEnabled = currentSettings.keyboardMultiSelect;
|
||||||
var isEnabled = settings.keyboardMultiSelect;
|
var isEnabled = settings.keyboardMultiSelect;
|
||||||
var oldPreset = currentSettings.keyboardPreset;
|
|
||||||
var newPreset = settings.keyboardPreset;
|
|
||||||
currentSettings = settings;
|
currentSettings = settings;
|
||||||
|
|
||||||
if (wasEnabled !== isEnabled || oldPreset !== newPreset) {
|
if (wasEnabled !== isEnabled) {
|
||||||
stop();
|
stop();
|
||||||
start(settings);
|
start(settings);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user