Skip to content

Commit

Permalink
Merge branch 't/13136' into major
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed May 4, 2015
2 parents 813cec6 + 687e1a9 commit 5111e74
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -9,6 +9,7 @@ Fixed Issues:
* Toolbar configurators:
* [#13185](http://dev.ckeditor.com/ticket/13185): Fixed: Wrong position of the suggestion box if there is not enough space below the caret.
* [#13138](http://dev.ckeditor.com/ticket/13138): Fixed: The "Toggle empty elements" button label is unclear.
* [#13136](http://dev.ckeditor.com/ticket/13136): Fixed: Autocompleter is far too intrusive.

## CKEditor 4.5 Beta

Expand Down
6 changes: 4 additions & 2 deletions samples/toolbarconfigurator/js/abstracttoolbarmodifier.js
Expand Up @@ -342,8 +342,10 @@ if ( !Object.keys ) {
var btns = that.editorInstance.ui.instances;

for ( var i in btns ) {
btns[ i ].click = empty;
btns[ i ].onClick = empty;
if ( btns[ i ] ) {
btns[ i ].click = empty;
btns[ i ].onClick = empty;
}
}

if ( !that.isEditableVisible ) {
Expand Down
85 changes: 46 additions & 39 deletions samples/toolbarconfigurator/js/toolbartextmodifier.js
Expand Up @@ -82,8 +82,13 @@
].join( '' );

function hint( cm ) {
var data = setupData( cm ),
unused = that.getUnusedButtonsArray( that.actualConfig.toolbar, true, data.charsBetween ),
var data = setupData( cm );

if ( data.charsBetween === null ) {
return;
}

var unused = that.getUnusedButtonsArray( that.actualConfig.toolbar, true, data.charsBetween ),
to = cm.getCursor(),
from = CodeMirror.Pos( to.line, ( to.ch - ( data.charsBetween.length ) ) ),
token = cm.getTokenAt( to ),
Expand All @@ -109,16 +114,6 @@
this._handlers = [];
}

function completeIfNeeded( character ) {
return function completeIfNeeded( cm ) {
return complete( cm, function() {
var data = setupData( cm, character );

return data.closestSpecialChar !== character;
}, character );
};
}

function setupData( cm, character ) {
var result = {};

Expand All @@ -127,34 +122,45 @@

result[ 'char' ] = character || result.tok.string.charAt( result.tok.string.length - 1 );

var curLineTillCur = cm.getRange( CodeMirror.Pos( result.cur.line, 0 ), result.cur ),
currLineTillCurReversed = curLineTillCur.split( '' ).reverse().join( '' ),
closestSpecialCharIndex = currLineTillCurReversed.search( /"|'|\{|\}|\[|\]|,|\:/ );
// Getting string between begin of line and cursor.
var curLineTillCur = cm.getRange( CodeMirror.Pos( result.cur.line, 0 ), result.cur );

closestSpecialCharIndex = ( closestSpecialCharIndex == -1 ? -1 : curLineTillCur.length - 1 - closestSpecialCharIndex );
result.closestSpecialChar = curLineTillCur.charAt( closestSpecialCharIndex );
// Reverse string.
var currLineTillCurReversed = curLineTillCur.split( '' ).reverse().join( '' );

//characters between cursor and special character
result.charsBetween = curLineTillCur.substring( closestSpecialCharIndex + 1, result.cur.ch )/* + result.char*/;
// Removing proper string definitions :
// FROM:
// R' ,'odeR' ,'odnU' [ :smeti{
// ^^^^^^ ^^^^^^
// TO:
// R' , [ :smeti{
currLineTillCurReversed = currLineTillCurReversed.replace( /(['|"]\w*['|"])/g, '' );

return result;
}

function complete( cm, pred, character ) {
var permitted = ( typeof pred === 'function' ? pred( cm, character ) : true );
// Matching letters till ' or " character and end string char.
// R' , [ :smeti{
// ^
result.charsBetween = currLineTillCurReversed.match( /(^\w*)(['|"])/ );

if ( permitted ) {
setTimeout( function() {
if ( !cm.state.completionActive ) {
CodeMirror.showHint( cm, hint, {
hintsClass: 'toolbar-modifier',
completeSingle: false
} );
}
if ( result.charsBetween ) {
result.endChar = result.charsBetween[ 2 ];

}, 100 );
// And reverse string (bring to original state).
result.charsBetween = result.charsBetween[ 1 ].split( '' ).reverse().join( '' );
}

return result;
}

function complete( cm ) {
setTimeout( function() {
if ( !cm.state.completionActive ) {
CodeMirror.showHint( cm, hint, {
hintsClass: 'toolbar-modifier',
completeSingle: false
} );
}
}, 100 );

return CodeMirror.Pass;
}

Expand All @@ -174,11 +180,12 @@
indentWithTabs: true,
theme: 'neo',
extraKeys: {
'Ctrl-Space': complete,
"'''": completeIfNeeded( "'" ),
"'\"'": completeIfNeeded( '"' ),
Backspace: completeIfNeeded( '"' ),
Delete: completeIfNeeded( '"' ),
'Left': complete,
'Right': complete,
"'''": complete,
"'\"'": complete,
Backspace: complete,
Delete: complete,
Tab: false,
'Shift-Tab': false
}
Expand All @@ -192,7 +199,7 @@
if ( completionData === undefined )
return;

cm.replaceSelection( data.closestSpecialChar );
cm.replaceSelection( data.endChar );
} );

this.codeContainer.on( 'change', function() {
Expand Down

0 comments on commit 5111e74

Please sign in to comment.