Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore shift click behavior for search button opening as a popup #920

Merged
merged 1 commit into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions ext/js/background/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -964,10 +964,10 @@ export class Backend {
// Command handlers

/**
* @param {undefined|{mode: 'existingOrNewTab'|'newTab', query?: string}} params
* @param {undefined|{mode: 'existingOrNewTab'|'newTab'|'popup', query?: string}} params
*/
async _onCommandOpenSearchPage(params) {
/** @type {'existingOrNewTab'|'newTab'} */
/** @type {'existingOrNewTab'|'newTab'|'popup'} */
let mode = 'existingOrNewTab';
let query = '';
if (typeof params === 'object' && params !== null) {
Expand Down Expand Up @@ -1023,6 +1023,8 @@ export class Backend {
case 'newTab':
await this._createTab(queryUrl);
return;
case 'popup':
return;
}
}

Expand All @@ -1034,10 +1036,10 @@ export class Backend {
}

/**
* @param {undefined|{mode: 'existingOrNewTab'|'newTab'}} params
* @param {undefined|{mode: 'existingOrNewTab'|'newTab'|'popup'}} params
*/
async _onCommandOpenSettingsPage(params) {
/** @type {'existingOrNewTab'|'newTab'} */
/** @type {'existingOrNewTab'|'newTab'|'popup'} */
let mode = 'existingOrNewTab';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to make mode an enum in this PR or separate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can make another pr for that later.

if (typeof params === 'object' && params !== null) {
mode = this._normalizeOpenSettingsPageMode(params.mode, mode);
Expand Down Expand Up @@ -2544,7 +2546,7 @@ export class Backend {
}

/**
* @param {'existingOrNewTab'|'newTab'} mode
* @param {'existingOrNewTab'|'newTab'|'popup'} mode
*/
async _openSettingsPage(mode) {
const manifest = chrome.runtime.getManifest();
Expand Down Expand Up @@ -2673,13 +2675,14 @@ export class Backend {

/**
* @param {unknown} mode
* @param {'existingOrNewTab'|'newTab'} defaultValue
* @returns {'existingOrNewTab'|'newTab'}
* @param {'existingOrNewTab'|'newTab'|'popup'} defaultValue
* @returns {'existingOrNewTab'|'newTab'|'popup'}
*/
_normalizeOpenSettingsPageMode(mode, defaultValue) {
switch (mode) {
case 'existingOrNewTab':
case 'newTab':
case 'popup':
return mode;
default:
return defaultValue;
Expand Down
10 changes: 9 additions & 1 deletion ext/js/pages/action-popup-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,15 @@ class DisplayController {
const result = customHandler(e);
if (typeof result !== 'undefined') { return; }
}
void this._api.commandExec(command, {mode: e.ctrlKey ? 'newTab' : 'existingOrNewTab'});

let mode = 'existingOrNewTab';
if (e.ctrlKey) {
mode = 'newTab';
} else if (e.shiftKey) {
mode = 'popup';
}

void this._api.commandExec(command, {mode: mode});
e.preventDefault();
};
/**
Expand Down