mirror of
https://github.com/discourse/discourse.git
synced 2025-06-07 15:44:41 +08:00
DEV: Remove modKeysPressed
(#27408)
It was added when removing `{{action}}` modifiers from the app, but we already had `wantsNewWindow` so use that instead.
This commit is contained in:
@ -4,8 +4,8 @@ import { alias, gt } from "@ember/object/computed";
|
|||||||
import { service } from "@ember/service";
|
import { service } from "@ember/service";
|
||||||
import { Promise } from "rsvp";
|
import { Promise } from "rsvp";
|
||||||
import { setting } from "discourse/lib/computed";
|
import { setting } from "discourse/lib/computed";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { groupPath } from "discourse/lib/url";
|
import { groupPath } from "discourse/lib/url";
|
||||||
import { modKeysPressed } from "discourse/lib/utilities";
|
|
||||||
import CardContentsBase from "discourse/mixins/card-contents-base";
|
import CardContentsBase from "discourse/mixins/card-contents-base";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
import CleansUp from "discourse/mixins/cleans-up";
|
||||||
import discourseComputed from "discourse-common/utils/decorators";
|
import discourseComputed from "discourse-common/utils/decorators";
|
||||||
@ -14,6 +14,7 @@ const maxMembersToDisplay = 10;
|
|||||||
|
|
||||||
export default Component.extend(CardContentsBase, CleansUp, {
|
export default Component.extend(CardContentsBase, CleansUp, {
|
||||||
composer: service(),
|
composer: service(),
|
||||||
|
|
||||||
elementId: "group-card",
|
elementId: "group-card",
|
||||||
mentionSelector: "a.mention-group",
|
mentionSelector: "a.mention-group",
|
||||||
classNames: ["no-bg", "group-card"],
|
classNames: ["no-bg", "group-card"],
|
||||||
@ -88,10 +89,11 @@ export default Component.extend(CardContentsBase, CleansUp, {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
handleShowGroup(group, event) {
|
handleShowGroup(group, event) {
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
event?.preventDefault();
|
|
||||||
|
event.preventDefault();
|
||||||
// Invokes `showGroup` argument. Convert to `this.args.showGroup` when
|
// Invokes `showGroup` argument. Convert to `this.args.showGroup` when
|
||||||
// refactoring this to a glimmer component.
|
// refactoring this to a glimmer component.
|
||||||
this.showGroup(group);
|
this.showGroup(group);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Component from "@ember/component";
|
import Component from "@ember/component";
|
||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { logSearchLinkClick } from "discourse/lib/search";
|
import { logSearchLinkClick } from "discourse/lib/search";
|
||||||
import { modKeysPressed } from "discourse/lib/utilities";
|
|
||||||
|
|
||||||
export default Component.extend({
|
export default Component.extend({
|
||||||
tagName: "div",
|
tagName: "div",
|
||||||
@ -13,9 +13,10 @@ export default Component.extend({
|
|||||||
@action
|
@action
|
||||||
logClick(topicId, event) {
|
logClick(topicId, event) {
|
||||||
// Avoid click logging when any modifier keys are pressed.
|
// Avoid click logging when any modifier keys are pressed.
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.searchLogId && topicId) {
|
if (this.searchLogId && topicId) {
|
||||||
logSearchLinkClick({
|
logSearchLinkClick({
|
||||||
searchLogId: this.searchLogId,
|
searchLogId: this.searchLogId,
|
||||||
|
@ -4,10 +4,10 @@ import TopicEntrance from "discourse/components/topic-list/topic-entrance";
|
|||||||
import TopicPostBadges from "discourse/components/topic-post-badges";
|
import TopicPostBadges from "discourse/components/topic-post-badges";
|
||||||
import TopicStatus from "discourse/components/topic-status";
|
import TopicStatus from "discourse/components/topic-status";
|
||||||
import formatAge from "discourse/helpers/format-age";
|
import formatAge from "discourse/helpers/format-age";
|
||||||
import { modKeysPressed } from "discourse/lib/utilities";
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
|
|
||||||
const onTimestampClick = function (event) {
|
const onTimestampClick = function (event) {
|
||||||
if (modKeysPressed(event).length) {
|
if (wantsNewWindow(event)) {
|
||||||
// Allow opening the link in a new tab/window
|
// Allow opening the link in a new tab/window
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
|
@ -5,9 +5,10 @@ import { dasherize } from "@ember/string";
|
|||||||
import { isEmpty } from "@ember/utils";
|
import { isEmpty } from "@ember/utils";
|
||||||
import { propertyNotEqual, setting } from "discourse/lib/computed";
|
import { propertyNotEqual, setting } from "discourse/lib/computed";
|
||||||
import { durationTiny } from "discourse/lib/formatter";
|
import { durationTiny } from "discourse/lib/formatter";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { prioritizeNameInUx } from "discourse/lib/settings";
|
import { prioritizeNameInUx } from "discourse/lib/settings";
|
||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
import { escapeExpression, modKeysPressed } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
import CanCheckEmails from "discourse/mixins/can-check-emails";
|
||||||
import CardContentsBase from "discourse/mixins/card-contents-base";
|
import CardContentsBase from "discourse/mixins/card-contents-base";
|
||||||
import CleansUp from "discourse/mixins/cleans-up";
|
import CleansUp from "discourse/mixins/cleans-up";
|
||||||
@ -233,10 +234,11 @@ export default Component.extend(CardContentsBase, CanCheckEmails, CleansUp, {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
handleShowUser(user, event) {
|
handleShowUser(user, event) {
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
event?.preventDefault();
|
|
||||||
|
event.preventDefault();
|
||||||
// Invokes `showUser` argument. Convert to `this.args.showUser` when
|
// Invokes `showUser` argument. Convert to `this.args.showUser` when
|
||||||
// refactoring this to a glimmer component.
|
// refactoring this to a glimmer component.
|
||||||
this.showUser(user);
|
this.showUser(user);
|
||||||
|
@ -2,8 +2,8 @@ import Controller from "@ember/controller";
|
|||||||
import { action } from "@ember/object";
|
import { action } from "@ember/object";
|
||||||
import { alias, or, readOnly } from "@ember/object/computed";
|
import { alias, or, readOnly } from "@ember/object/computed";
|
||||||
import { ajax } from "discourse/lib/ajax";
|
import { ajax } from "discourse/lib/ajax";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||||
import { modKeysPressed } from "discourse/lib/utilities";
|
|
||||||
import { getWebauthnCredential } from "discourse/lib/webauthn";
|
import { getWebauthnCredential } from "discourse/lib/webauthn";
|
||||||
import PasswordValidation from "discourse/mixins/password-validation";
|
import PasswordValidation from "discourse/mixins/password-validation";
|
||||||
import { SECOND_FACTOR_METHODS } from "discourse/models/user";
|
import { SECOND_FACTOR_METHODS } from "discourse/models/user";
|
||||||
@ -66,10 +66,11 @@ export default Controller.extend(PasswordValidation, {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
done(event) {
|
done(event) {
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
event?.preventDefault();
|
|
||||||
|
event.preventDefault();
|
||||||
this.set("redirected", true);
|
this.set("redirected", true);
|
||||||
DiscourseURL.redirectTo(this.redirectTo || "/");
|
DiscourseURL.redirectTo(this.redirectTo || "/");
|
||||||
},
|
},
|
||||||
|
@ -19,11 +19,12 @@ import { ajax } from "discourse/lib/ajax";
|
|||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import { BookmarkFormData } from "discourse/lib/bookmark-form-data";
|
import { BookmarkFormData } from "discourse/lib/bookmark-form-data";
|
||||||
import { resetCachedTopicList } from "discourse/lib/cached-topic-list";
|
import { resetCachedTopicList } from "discourse/lib/cached-topic-list";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { buildQuote } from "discourse/lib/quote";
|
import { buildQuote } from "discourse/lib/quote";
|
||||||
import QuoteState from "discourse/lib/quote-state";
|
import QuoteState from "discourse/lib/quote-state";
|
||||||
import { extractLinkMeta } from "discourse/lib/render-topic-featured-link";
|
import { extractLinkMeta } from "discourse/lib/render-topic-featured-link";
|
||||||
import DiscourseURL, { userPath } from "discourse/lib/url";
|
import DiscourseURL, { userPath } from "discourse/lib/url";
|
||||||
import { escapeExpression, modKeysPressed } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
import { bufferedProperty } from "discourse/mixins/buffered-content";
|
||||||
import Bookmark, { AUTO_DELETE_PREFERENCES } from "discourse/models/bookmark";
|
import Bookmark, { AUTO_DELETE_PREFERENCES } from "discourse/models/bookmark";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
@ -339,10 +340,11 @@ export default Controller.extend(bufferedProperty("model"), {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
jumpTop(event) {
|
jumpTop(event) {
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
event?.preventDefault();
|
|
||||||
|
event.preventDefault();
|
||||||
DiscourseURL.routeTo(this.get("model.firstPostUrl"), {
|
DiscourseURL.routeTo(this.get("model.firstPostUrl"), {
|
||||||
skipIfOnScreen: false,
|
skipIfOnScreen: false,
|
||||||
keepFilter: true,
|
keepFilter: true,
|
||||||
|
@ -463,12 +463,6 @@ export async function inCodeBlock(text, pos) {
|
|||||||
return CODE_TOKEN_TYPES.includes(type);
|
return CODE_TOKEN_TYPES.includes(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return an array of modifier keys that are pressed during a given `MouseEvent`
|
|
||||||
// or `KeyboardEvent`.
|
|
||||||
export function modKeysPressed(event) {
|
|
||||||
return ["alt", "shift", "meta", "ctrl"].filter((key) => event[`${key}Key`]);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function translateModKey(string) {
|
export function translateModKey(string) {
|
||||||
const { isApple } = capabilities;
|
const { isApple } = capabilities;
|
||||||
// Apple device users are used to glyphs for shortcut keys
|
// Apple device users are used to glyphs for shortcut keys
|
||||||
|
@ -21,6 +21,7 @@ import prepareFormTemplateData, {
|
|||||||
} from "discourse/lib/form-template-validation";
|
} from "discourse/lib/form-template-validation";
|
||||||
import { shortDate } from "discourse/lib/formatter";
|
import { shortDate } from "discourse/lib/formatter";
|
||||||
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
import { disableImplicitInjections } from "discourse/lib/implicit-injections";
|
||||||
|
import { wantsNewWindow } from "discourse/lib/intercept-click";
|
||||||
import { buildQuote } from "discourse/lib/quote";
|
import { buildQuote } from "discourse/lib/quote";
|
||||||
import renderTags from "discourse/lib/render-tags";
|
import renderTags from "discourse/lib/render-tags";
|
||||||
import { emojiUnescape } from "discourse/lib/text";
|
import { emojiUnescape } from "discourse/lib/text";
|
||||||
@ -29,7 +30,7 @@ import {
|
|||||||
uploadIcon,
|
uploadIcon,
|
||||||
} from "discourse/lib/uploads";
|
} from "discourse/lib/uploads";
|
||||||
import DiscourseURL from "discourse/lib/url";
|
import DiscourseURL from "discourse/lib/url";
|
||||||
import { escapeExpression, modKeysPressed } from "discourse/lib/utilities";
|
import { escapeExpression } from "discourse/lib/utilities";
|
||||||
import Category from "discourse/models/category";
|
import Category from "discourse/models/category";
|
||||||
import Composer, {
|
import Composer, {
|
||||||
CREATE_TOPIC,
|
CREATE_TOPIC,
|
||||||
@ -645,10 +646,11 @@ export default class ComposerService extends Service {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
viewNewReply(event) {
|
viewNewReply(event) {
|
||||||
if (event && modKeysPressed(event).length > 0) {
|
if (wantsNewWindow(event)) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
event?.preventDefault();
|
|
||||||
|
event.preventDefault();
|
||||||
DiscourseURL.routeTo(this.get("model.createdPost.url"));
|
DiscourseURL.routeTo(this.get("model.createdPost.url"));
|
||||||
this.close();
|
this.close();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,4 @@
|
|||||||
import { getOwner } from "@ember/application";
|
import { getOwner } from "@ember/application";
|
||||||
import { click, render } from "@ember/test-helpers";
|
|
||||||
import { hbs } from "ember-cli-htmlbars";
|
|
||||||
import { setupTest } from "ember-qunit";
|
import { setupTest } from "ember-qunit";
|
||||||
import Handlebars from "handlebars";
|
import Handlebars from "handlebars";
|
||||||
import { module, test } from "qunit";
|
import { module, test } from "qunit";
|
||||||
@ -18,7 +16,6 @@ import {
|
|||||||
inCodeBlock,
|
inCodeBlock,
|
||||||
initializeDefaultHomepage,
|
initializeDefaultHomepage,
|
||||||
mergeSortedLists,
|
mergeSortedLists,
|
||||||
modKeysPressed,
|
|
||||||
setCaretPosition,
|
setCaretPosition,
|
||||||
setDefaultHomepage,
|
setDefaultHomepage,
|
||||||
slugify,
|
slugify,
|
||||||
@ -29,7 +26,6 @@ import {
|
|||||||
mdTableNonUniqueHeadings,
|
mdTableNonUniqueHeadings,
|
||||||
mdTableSpecialChars,
|
mdTableSpecialChars,
|
||||||
} from "discourse/tests/fixtures/md-table";
|
} from "discourse/tests/fixtures/md-table";
|
||||||
import { setupRenderingTest } from "discourse/tests/helpers/component-test";
|
|
||||||
import { chromeTest } from "discourse/tests/helpers/qunit-helpers";
|
import { chromeTest } from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
|
||||||
module("Unit | Utilities", function (hooks) {
|
module("Unit | Utilities", function (hooks) {
|
||||||
@ -271,54 +267,6 @@ module("Unit | Utilities", function (hooks) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
module("Unit | Utilities | modKeysPressed", function (hooks) {
|
|
||||||
setupRenderingTest(hooks);
|
|
||||||
|
|
||||||
test("returns an array of modifier keys pressed during keyboard or mouse event", async function (assert) {
|
|
||||||
let i = 0;
|
|
||||||
|
|
||||||
this.handleClick = (event) => {
|
|
||||||
if (i === 0) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), []);
|
|
||||||
} else if (i === 1) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), ["alt"]);
|
|
||||||
} else if (i === 2) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), ["shift"]);
|
|
||||||
} else if (i === 3) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), ["meta"]);
|
|
||||||
} else if (i === 4) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), ["ctrl"]);
|
|
||||||
} else if (i === 5) {
|
|
||||||
assert.deepEqual(modKeysPressed(event), [
|
|
||||||
"alt",
|
|
||||||
"shift",
|
|
||||||
"meta",
|
|
||||||
"ctrl",
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
await render(hbs`<button id="btn" {{on "click" this.handleClick}} />`);
|
|
||||||
|
|
||||||
await click("#btn");
|
|
||||||
i++;
|
|
||||||
await click("#btn", { altKey: true });
|
|
||||||
i++;
|
|
||||||
await click("#btn", { shiftKey: true });
|
|
||||||
i++;
|
|
||||||
await click("#btn", { metaKey: true });
|
|
||||||
i++;
|
|
||||||
await click("#btn", { ctrlKey: true });
|
|
||||||
i++;
|
|
||||||
await click("#btn", {
|
|
||||||
altKey: true,
|
|
||||||
shiftKey: true,
|
|
||||||
metaKey: true,
|
|
||||||
ctrlKey: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
module("Unit | Utilities | clipboard", function (hooks) {
|
module("Unit | Utilities | clipboard", function (hooks) {
|
||||||
setupTest(hooks);
|
setupTest(hooks);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user