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

[settings-view] Fix Package keymap compatibility check #1161

Merged
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
12 changes: 9 additions & 3 deletions packages/settings-view/lib/package-keymap-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import KeybindingsPanel from './keybindings-panel'
export default class PackageKeymapView {
constructor (pack) {
this.pack = pack
this.otherPlatformPattern = new RegExp(`\\.platform-(?!${_.escapeRegExp(process.platform)}\\b)`)
this.namespace = this.pack.name
this.disposables = new CompositeDisposable()
etch.initialize(this)
Expand Down Expand Up @@ -128,8 +127,8 @@ export default class PackageKeymapView {
continue
}

if (this.otherPlatformPattern.test(selector)) {
continue
if (!this.selectorIsCompatibleWithPlatform(selector)) {
continue;
}

const keyBindingRow = document.createElement('tr')
Expand Down Expand Up @@ -183,4 +182,11 @@ export default class PackageKeymapView {

atom.clipboard.write(content)
}

selectorIsCompatibleWithPlatform(selector, platform = process.platform) {
const otherPlatformPattern = new RegExp(`\\.platform-(?!${_.escapeRegExp(platform)}\\b)`);
const currentPlatformPattern = new RegExp(`\\.platform-(${_.escapeRegExp(platform)}\\b)`);

return !(otherPlatformPattern.test(selector) && !currentPlatformPattern.test(selector));
}
}
35 changes: 35 additions & 0 deletions packages/settings-view/spec/package-keymap-view-spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

const PackageKeymapView = require("../lib/package-keymap-view.js");
let view;

describe("PackageKeymapView", () => {

beforeEach(() => {
// Just prevent this stuff from calling through, it doesn't matter for this test
spyOn(atom.packages, "getLoadedPackage").andReturn({ keymaps: [] });

view = new PackageKeymapView({
name: "test-package"
});
});

it("should say a selector with no platform listed is compatible with the current one", () => {
expect(view.selectorIsCompatibleWithPlatform("atom-text-editor", "win32")).toBe(true);
});

it("should say a selector with a platform other than the current is not compatible", () => {
expect(view.selectorIsCompatibleWithPlatform(".platform-darwin", "linux")).toBe(false);
expect(view.selectorIsCompatibleWithPlatform(".platform-win32", "darwin")).toBe(false);
});

it("should say a selector with the current platform listed is compatible", () => {
expect(view.selectorIsCompatibleWithPlatform(".platform-linux", "linux")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-win32", "win32")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-darwin", "darwin")).toBe(true);
});

it("should say a selector with the current platform and others listed is compatible", () => {
expect(view.selectorIsCompatibleWithPlatform(".platform-linux, .platform-win32", "win32")).toBe(true);
expect(view.selectorIsCompatibleWithPlatform(".platform-linux, .platform-win32", "linux")).toBe(true);
});
});
Loading