Skip to content

Commit 5e6732b

Browse files
committed
iconview: enhance entry selection handling with keyboard and mouse events
- Intoduces icon-view entry selection json to send along with selection/activation instead of just selected index - This information can be helpful in core side to know if any mouse key was pressed along with selection of item to execute relevant logic if exist. - i.e sidebar->border popup dialog allows to overwrite borders if shift key was pressed along border item selection Change-Id: I09ced62b58fb906abc7279fa2c77ba06a0743eab Signed-off-by: Parth Raiyani <[email protected]>
1 parent df06155 commit 5e6732b

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

browser/src/control/jsdialog/Widget.IconView.ts

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,36 @@ function _iconViewEntry(
185185
}
186186
builder._preventDocumentLosingFocusOnClick(entryContainer);
187187

188-
entryContainer.addEventListener('keydown', function (e: KeyboardEvent) {
189-
if (e.key !== 'Enter' && e.key !== ' ' && e.code !== 'Space') return;
188+
const getUNOKeyCodeWithModifiers = function (
189+
e: KeyboardEvent,
190+
builder: any,
191+
app: any,
192+
): number {
193+
let keyCode = e.keyCode;
194+
195+
const shift =
196+
keyCode === builder.map.keyboard.keyCodes.SHIFT
197+
? app.UNOModifier.SHIFT
198+
: 0;
199+
const ctrl =
200+
keyCode === builder.map.keyboard.keyCodes.CTRL || e.metaKey
201+
? app.UNOModifier.CTRL
202+
: 0;
203+
const alt =
204+
keyCode === builder.map.keyboard.keyCodes.ALT ? app.UNOModifier.ALT : 0;
205+
206+
const modifier = shift | ctrl | alt;
207+
208+
if (modifier) {
209+
keyCode = e.key.toUpperCase().charCodeAt(0);
210+
keyCode = builder.map.keyboard._toUNOKeyCode(keyCode);
211+
keyCode |= modifier;
212+
}
190213

214+
return keyCode;
215+
};
216+
217+
entryContainer.addEventListener('keydown', function (e: KeyboardEvent) {
191218
if (e.key === ' ' || e.code === 'Space')
192219
parentContainer.builderCallback(
193220
'iconview',
@@ -202,6 +229,23 @@ function _iconViewEntry(
202229
entry.row,
203230
builder,
204231
);
232+
else {
233+
parentContainer.builderCallback(
234+
'iconview',
235+
'keypress',
236+
getUNOKeyCodeWithModifiers(e, builder, app),
237+
builder,
238+
);
239+
}
240+
});
241+
242+
entryContainer.addEventListener('keyup', function (e: KeyboardEvent) {
243+
parentContainer.builderCallback(
244+
'iconview',
245+
'keyrelease',
246+
getUNOKeyCodeWithModifiers(e, builder, app),
247+
builder,
248+
);
205249
});
206250
}
207251
}

0 commit comments

Comments
 (0)