Skip to content

Commit

Permalink
match native Windows Home/End key behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinansfield committed Sep 25, 2017
1 parent b3e9f8b commit f2e9818
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
22 changes: 17 additions & 5 deletions debug/simplemde.debug.js

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions debug/simplemde.js
Original file line number Diff line number Diff line change
Expand Up @@ -14651,8 +14651,14 @@ var CodeMirrorSpellChecker = require("codemirror-spell-checker");
var marked;


// Some variables
var isMac = /Mac/.test(navigator.platform);
// Platform/Browser detection
// borrowed from https://github.com/codemirror/CodeMirror/blob/master/src/util/browser.js
var userAgent = navigator.userAgent;
var platform = navigator.platform;
var edge = /Edge\/(\d+)/.exec(userAgent);
var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
var mac = ios || /Mac/.test(platform);
var windows = /win/i.test(platform);

// Mapping of actions that can be bound to keyboard shortcuts or toolbar buttons
var bindings = {
Expand Down Expand Up @@ -14719,7 +14725,7 @@ var isMobile = function() {
* Fix shortcut. Mac use Command, others use Ctrl.
*/
function fixShortcut(name) {
if(isMac) {
if(mac) {
name = name.replace("Ctrl", "Cmd");
} else {
name = name.replace("Cmd", "Ctrl");
Expand All @@ -14739,7 +14745,7 @@ function createIcon(options, enableTooltips, shortcuts) {
if(options.title && enableTooltips) {
el.title = createTootlip(options.title, options.action, shortcuts);

if(isMac) {
if(mac) {
el.title = el.title.replace("Ctrl", "⌘");
el.title = el.title.replace("Alt", "⌥");
}
Expand Down Expand Up @@ -16092,6 +16098,12 @@ SimpleMDE.prototype.render = function(el) {
if(cm.getOption("fullScreen")) toggleFullScreen(self);
};

// match Windows Home/End behaviour
if(windows) {
keyMaps["Home"] = "goLineLeftSmart";
keyMaps["End"] = "goLineRight";
}

document.addEventListener("keydown", function(e) {
e = e || window.event;

Expand Down
4 changes: 2 additions & 2 deletions dist/simplemde.min.js

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/js/simplemde.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ var CodeMirrorSpellChecker = require("codemirror-spell-checker");
var marked;


// Some variables
var isMac = /Mac/.test(navigator.platform);
// Platform/Browser detection
// borrowed from https://github.com/codemirror/CodeMirror/blob/master/src/util/browser.js
var userAgent = navigator.userAgent;
var platform = navigator.platform;
var edge = /Edge\/(\d+)/.exec(userAgent);
var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
var mac = ios || /Mac/.test(platform);
var windows = /win/i.test(platform);

// Mapping of actions that can be bound to keyboard shortcuts or toolbar buttons
var bindings = {
Expand Down Expand Up @@ -85,7 +91,7 @@ var isMobile = function() {
* Fix shortcut. Mac use Command, others use Ctrl.
*/
function fixShortcut(name) {
if(isMac) {
if(mac) {
name = name.replace("Ctrl", "Cmd");
} else {
name = name.replace("Cmd", "Ctrl");
Expand All @@ -105,7 +111,7 @@ function createIcon(options, enableTooltips, shortcuts) {
if(options.title && enableTooltips) {
el.title = createTootlip(options.title, options.action, shortcuts);

if(isMac) {
if(mac) {
el.title = el.title.replace("Ctrl", "⌘");
el.title = el.title.replace("Alt", "⌥");
}
Expand Down Expand Up @@ -1458,6 +1464,12 @@ SimpleMDE.prototype.render = function(el) {
if(cm.getOption("fullScreen")) toggleFullScreen(self);
};

// match Windows Home/End behaviour
if(windows) {
keyMaps["Home"] = "goLineLeftSmart";
keyMaps["End"] = "goLineRight";
}

document.addEventListener("keydown", function(e) {
e = e || window.event;

Expand Down

0 comments on commit f2e9818

Please sign in to comment.