caseSensitive option added to autocomplete
This commit is contained in:
parent
371a7b2d14
commit
89601c3115
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||
* @version 5.11.0
|
||||
* @date 2017-11-22
|
||||
* @date 2017-12-02
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -25,7 +25,7 @@
|
|||
*
|
||||
* @author Jos de Jong, <wjosdejong@gmail.com>
|
||||
* @version 5.11.0
|
||||
* @date 2017-11-22
|
||||
* @date 2017-12-02
|
||||
*/
|
||||
(function webpackUniversalModuleDefinition(root, factory) {
|
||||
if(typeof exports === 'object' && typeof module === 'object')
|
||||
|
@ -16031,6 +16031,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
function completely(config) {
|
||||
config = config || {};
|
||||
config.confirmKeys = config.confirmKeys || [39, 35, 9] // right, end, tab
|
||||
config.caseSensitive = config.caseSensitive || false // autocomplete case sensitive
|
||||
|
||||
var fontSize = '';
|
||||
var fontFamily = '';
|
||||
|
@ -16075,7 +16076,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
rows = [];
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i].indexOf(token) !== 0) { continue; }
|
||||
|
||||
if ( (config.caseSensitive && array[i].indexOf(token) !== 0)
|
||||
||(!config.caseSensitive && array[i].toLowerCase().indexOf(token.toLowerCase()) !== 0)) { continue; }
|
||||
|
||||
var divRow = document.createElement('div');
|
||||
divRow.className = 'item';
|
||||
//divRow.style.color = config.color;
|
||||
|
@ -16090,7 +16094,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
if (rows.length === 0) {
|
||||
return; // nothing to show.
|
||||
}
|
||||
if (rows.length === 1 && token === rows[0].__hint) {
|
||||
if (rows.length === 1 && ( (token.toLowerCase() === rows[0].__hint.toLowerCase() && !config.caseSensitive)
|
||||
||(token === rows[0].__hint && config.caseSensitive))){
|
||||
return; // do not show the dropDown if it has only one element which matches what we have just displayed.
|
||||
}
|
||||
|
||||
|
@ -16276,8 +16281,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
|
||||
for (var i = 0; i < optionsLength; i++) {
|
||||
var opt = this.options[i];
|
||||
if (opt.indexOf(token) === 0) { // <-- how about upperCase vs. lowercase
|
||||
this.elementHint.innerText = leftSide + opt;
|
||||
if ( (!config.caseSensitive && opt.toLowerCase().indexOf(token.toLowerCase()) === 0)
|
||||
|| (config.caseSensitive && opt.indexOf(token) === 0)) { // <-- how about upperCase vs. lowercase
|
||||
this.elementHint.innerText = leftSide + token + opt.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + opt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16311,6 +16318,10 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return;
|
||||
}
|
||||
|
||||
var text = this.element.innerText;
|
||||
text = text.replace('\n', '');
|
||||
var startFrom = this.startFrom;
|
||||
|
||||
if (config.confirmKeys.indexOf(keyCode) >= 0) { // (autocomplete triggered)
|
||||
if (keyCode == 9) {
|
||||
if (this.elementHint.innerText.length == 0) {
|
||||
|
@ -16318,8 +16329,8 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
}
|
||||
if (this.elementHint.innerText.length > 0) { // if there is a hint
|
||||
if (this.element.innerText != this.elementHint.innerText) {
|
||||
this.element.innerText = this.elementHint.innerText;
|
||||
if (this.element.innerText != this.elementHint.realInnerText) {
|
||||
this.element.innerText = this.elementHint.realInnerText;
|
||||
rs.hideDropDown();
|
||||
setEndOfContenteditable(this.element);
|
||||
if (keyCode == 9) {
|
||||
|
@ -16346,7 +16357,7 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
return;
|
||||
}
|
||||
|
||||
this.element.innerText = this.elementHint.innerText;
|
||||
this.element.innerText = this.elementHint.realInnerText;
|
||||
rs.hideDropDown();
|
||||
setEndOfContenteditable(this.element);
|
||||
e.preventDefault();
|
||||
|
@ -16356,18 +16367,22 @@ return /******/ (function(modules) { // webpackBootstrap
|
|||
}
|
||||
|
||||
if (keyCode == 40) { // down
|
||||
var token = text.substring(this.startFrom);
|
||||
var m = dropDownController.move(+1);
|
||||
if (m == '') { rs.onArrowDown(); }
|
||||
this.elementHint.innerText = leftSide + m;
|
||||
this.elementHint.innerText = leftSide + token + m.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + m;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyCode == 38) { // up
|
||||
var token = text.substring(this.startFrom);
|
||||
var m = dropDownController.move(-1);
|
||||
if (m == '') { rs.onArrowUp(); }
|
||||
this.elementHint.innerText = leftSide + m;
|
||||
this.elementHint.innerText = leftSide + token + m.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + m;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -162,6 +162,10 @@ Constructs a new JSONEditor.
|
|||
|
||||
Indicate the KeyCodes for trigger confirm completion, by default those keys are: [39, 35, 9] which are the code for [right, end, tab]
|
||||
|
||||
- `{boolean} caseSensitive`
|
||||
|
||||
Indicate if the autocomplete is going to be strict case-sensitive to match the options.
|
||||
|
||||
- `{Function} getOptions (text: string, path: string[], input: string, editor: JSONEditor)`
|
||||
|
||||
This function will return your possible options for create the autocomplete selection, you can control dynamically which options you want to display according to the current active editing node.
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
var options = {
|
||||
autocomplete: {
|
||||
confirmKeys: [39, 35, 9, 190], // Confirm Autocomplete Keys: [right, end, tab, '.'] // By default are only [right, end, tab]
|
||||
caseSensitive: true,
|
||||
|
||||
getOptions: function (text, path, input, editor) {
|
||||
if (!text.startsWith(activationChar) || input !== 'value') return [];
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
function completely(config) {
|
||||
config = config || {};
|
||||
config.confirmKeys = config.confirmKeys || [39, 35, 9] // right, end, tab
|
||||
config.caseSensitive = config.caseSensitive || false // autocomplete case sensitive
|
||||
|
||||
var fontSize = '';
|
||||
var fontFamily = '';
|
||||
|
@ -47,7 +48,10 @@ function completely(config) {
|
|||
|
||||
rows = [];
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
if (array[i].indexOf(token) !== 0) { continue; }
|
||||
|
||||
if ( (config.caseSensitive && array[i].indexOf(token) !== 0)
|
||||
||(!config.caseSensitive && array[i].toLowerCase().indexOf(token.toLowerCase()) !== 0)) { continue; }
|
||||
|
||||
var divRow = document.createElement('div');
|
||||
divRow.className = 'item';
|
||||
//divRow.style.color = config.color;
|
||||
|
@ -62,7 +66,8 @@ function completely(config) {
|
|||
if (rows.length === 0) {
|
||||
return; // nothing to show.
|
||||
}
|
||||
if (rows.length === 1 && token === rows[0].__hint) {
|
||||
if (rows.length === 1 && ( (token.toLowerCase() === rows[0].__hint.toLowerCase() && !config.caseSensitive)
|
||||
||(token === rows[0].__hint && config.caseSensitive))){
|
||||
return; // do not show the dropDown if it has only one element which matches what we have just displayed.
|
||||
}
|
||||
|
||||
|
@ -248,8 +253,10 @@ function completely(config) {
|
|||
|
||||
for (var i = 0; i < optionsLength; i++) {
|
||||
var opt = this.options[i];
|
||||
if (opt.indexOf(token) === 0) { // <-- how about upperCase vs. lowercase
|
||||
this.elementHint.innerText = leftSide + opt;
|
||||
if ( (!config.caseSensitive && opt.toLowerCase().indexOf(token.toLowerCase()) === 0)
|
||||
|| (config.caseSensitive && opt.indexOf(token) === 0)) { // <-- how about upperCase vs. lowercase
|
||||
this.elementHint.innerText = leftSide + token + opt.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + opt;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -283,6 +290,10 @@ function completely(config) {
|
|||
return;
|
||||
}
|
||||
|
||||
var text = this.element.innerText;
|
||||
text = text.replace('\n', '');
|
||||
var startFrom = this.startFrom;
|
||||
|
||||
if (config.confirmKeys.indexOf(keyCode) >= 0) { // (autocomplete triggered)
|
||||
if (keyCode == 9) {
|
||||
if (this.elementHint.innerText.length == 0) {
|
||||
|
@ -290,8 +301,8 @@ function completely(config) {
|
|||
}
|
||||
}
|
||||
if (this.elementHint.innerText.length > 0) { // if there is a hint
|
||||
if (this.element.innerText != this.elementHint.innerText) {
|
||||
this.element.innerText = this.elementHint.innerText;
|
||||
if (this.element.innerText != this.elementHint.realInnerText) {
|
||||
this.element.innerText = this.elementHint.realInnerText;
|
||||
rs.hideDropDown();
|
||||
setEndOfContenteditable(this.element);
|
||||
if (keyCode == 9) {
|
||||
|
@ -318,7 +329,7 @@ function completely(config) {
|
|||
return;
|
||||
}
|
||||
|
||||
this.element.innerText = this.elementHint.innerText;
|
||||
this.element.innerText = this.elementHint.realInnerText;
|
||||
rs.hideDropDown();
|
||||
setEndOfContenteditable(this.element);
|
||||
e.preventDefault();
|
||||
|
@ -328,18 +339,22 @@ function completely(config) {
|
|||
}
|
||||
|
||||
if (keyCode == 40) { // down
|
||||
var token = text.substring(this.startFrom);
|
||||
var m = dropDownController.move(+1);
|
||||
if (m == '') { rs.onArrowDown(); }
|
||||
this.elementHint.innerText = leftSide + m;
|
||||
this.elementHint.innerText = leftSide + token + m.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + m;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
if (keyCode == 38) { // up
|
||||
var token = text.substring(this.startFrom);
|
||||
var m = dropDownController.move(-1);
|
||||
if (m == '') { rs.onArrowUp(); }
|
||||
this.elementHint.innerText = leftSide + m;
|
||||
this.elementHint.innerText = leftSide + token + m.substring(token.length);
|
||||
this.elementHint.realInnerText = leftSide + m;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
return;
|
||||
|
|
Loading…
Reference in New Issue