forked from josdejong/jsoneditor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed josdejong#154: Implemented shortcut keys to format and compact …
…JSON when in mode `text` or `code`.
- Loading branch information
Showing
9 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
* | ||
* @author Jos de Jong, <[email protected]> | ||
* @version 3.1.3-SNAPSHOT | ||
* @date 2014-09-13 | ||
* @date 2015-01-23 | ||
*/ | ||
(function webpackUniversalModuleDefinition(root, factory) { | ||
if(typeof exports === 'object' && typeof module === 'object') | ||
|
@@ -1120,6 +1120,9 @@ return /******/ (function(modules) { // webpackBootstrap | |
// prevent default submit action when the editor is located inside a form | ||
event.preventDefault(); | ||
}; | ||
this.frame.onkeydown = function (event) { | ||
me._onKeyDown(event); | ||
}; | ||
|
||
// create menu | ||
this.menu = document.createElement('div'); | ||
|
@@ -1129,7 +1132,7 @@ return /******/ (function(modules) { // webpackBootstrap | |
// create format button | ||
var buttonFormat = document.createElement('button'); | ||
buttonFormat.className = 'format'; | ||
buttonFormat.title = 'Format JSON data, with proper indentation and line feeds'; | ||
buttonFormat.title = 'Format JSON data, with proper indentation and line feeds (Ctrl+\\)'; | ||
this.menu.appendChild(buttonFormat); | ||
buttonFormat.onclick = function () { | ||
try { | ||
|
@@ -1143,7 +1146,7 @@ return /******/ (function(modules) { // webpackBootstrap | |
// create compact button | ||
var buttonCompact = document.createElement('button'); | ||
buttonCompact.className = 'compact'; | ||
buttonCompact.title = 'Compact JSON data, remove all whitespaces'; | ||
buttonCompact.title = 'Compact JSON data, remove all whitespaces (Ctrl+Shift+\\)'; | ||
this.menu.appendChild(buttonCompact); | ||
buttonCompact.onclick = function () { | ||
try { | ||
|
@@ -1228,6 +1231,31 @@ return /******/ (function(modules) { // webpackBootstrap | |
} | ||
}; | ||
|
||
/** | ||
* Event handler for keydown. Handles shortcut keys | ||
* @param {Event} event | ||
* @private | ||
*/ | ||
textmode._onKeyDown = function (event) { | ||
var keynum = event.which || event.keyCode; | ||
var handled = false; | ||
|
||
if (keynum == 220 && event.ctrlKey) { | ||
if (event.shiftKey) { // Ctrl+Shift+\ | ||
this.compact(); | ||
} | ||
else { // Ctrl+\ | ||
this.format(); | ||
} | ||
handled = true; | ||
} | ||
|
||
if (handled) { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
} | ||
}; | ||
|
||
/** | ||
* Detach the editor from the DOM | ||
* @private | ||
|
@@ -2618,7 +2646,7 @@ return /******/ (function(modules) { // webpackBootstrap | |
var node = this; | ||
var path = []; | ||
while (node) { | ||
var field = node.field || node.index; | ||
var field = node.field != undefined ? node.field : node.index; | ||
if (field !== undefined) { | ||
path.unshift(field); | ||
} | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters