Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
xdan committed Jan 10, 2018
1 parent 91d6827 commit 5a1ed6f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 19 deletions.
4 changes: 2 additions & 2 deletions build/jodit.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions build/jodit.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jodit",
"version": "3.1.4",
"version": "3.1.5",
"description": "Jodit is awesome and usefully wysiwyg editor with filebrowser",
"main": "index.js",
"scripts": {
Expand Down
23 changes: 10 additions & 13 deletions src/plugins/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class search extends Component {
return;
}

this.counterBox.style.display = this.queryInput.value.length ? 'inline-block' : 'none'
this.counterBox.style.display = this.queryInput.value.length ? 'inline-block' : 'none';

const sel: Selection = this.jodit.editorWindow.getSelection(),
range: Range = sel.rangeCount ? sel.getRangeAt(0) : this.jodit.editorDocument.createRange(),
Expand Down Expand Up @@ -178,18 +178,15 @@ export class search extends Component {
let range: Range = this.jodit.editorDocument.createRange();

try {

setTimeout(() => {
if (bound && bound.startContainer && bound.endContainer) {
range.setStart(bound.startContainer, <number>bound.startOffset);
range.setEnd(bound.endContainer, <number>bound.endOffset);
range.deleteContents();
let textNode: Node = this.jodit.editorDocument.createTextNode(this.replaceInput.value);
range.insertNode(textNode);
this.jodit.selection.select(textNode)
this.tryScrollToElement(textNode);
}
}, this.jodit.options.observer.timeout);
if (bound && bound.startContainer && bound.endContainer) {
range.setStart(bound.startContainer, <number>bound.startOffset);
range.setEnd(bound.endContainer, <number>bound.endOffset);
range.deleteContents();
const textNode: Node = this.jodit.editorDocument.createTextNode(this.replaceInput.value);
range.insertNode(textNode);
this.jodit.selection.select(textNode);
this.tryScrollToElement(textNode);
}
} catch (e) {

}
Expand Down
3 changes: 2 additions & 1 deletion src/styles/plugins/search.less
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@
height: 50%;
transition: background-color @timeout-button-active linear;
&:focus {
background-color: fade(@color-background-selection, 9);
//background-color: fade(@color-background-selection, 9);
box-shadow: inset 0px 0px 3px 0px fade(@color-border, 58);
}
}
}
Expand Down
52 changes: 52 additions & 0 deletions test/tests/pluginsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,58 @@ describe('Test plugins', function () {
expect(true).to.equal(editor.ownerDocument.activeElement === search.querySelector('.jodit_search-query'));
});
});
describe('CTRL + R', function () {
it('Should show search and replace form and query field must have focus', function () {
var editor = new Jodit('#editor_plugins_test', {
observer: {
timeout: 0
}
});

var search = editor.container.querySelector('.jodit_search');
expect(false).to.equal(search.classList.contains('jodit_search-active'));
simulateEvent('keydown', Jodit.KEY_R, editor.editor, function (options) {
options.ctrlKey = true
});
expect(true).to.equal(search.classList.contains('jodit_search-active'));
expect(true).to.equal(search.classList.contains('jodit_search-and-replace'));
expect(true).to.equal(editor.ownerDocument.activeElement === search.querySelector('.jodit_search-query'));
});
describe('Press Replace button', function () {
it('Should replace value form query field to value from replace field in editor', function () {
var editor = new Jodit('#editor_plugins_test', {
observer: {
timeout: 0
}
});

editor.setEditorValue('test test test')

var search = editor.container.querySelector('.jodit_search');
expect(false).to.equal(search.classList.contains('jodit_search-active'));
simulateEvent('keydown', Jodit.KEY_R, editor.editor, function (options) {
options.ctrlKey = true
});
expect(true).to.be.equal(search.classList.contains('jodit_search-active'));
expect(true).to.be.equal(search.classList.contains('jodit_search-and-replace'));
expect(true).to.be.equal(editor.ownerDocument.activeElement === search.querySelector('.jodit_search-query'));

var query = search.querySelector('.jodit_search-query');
var replace = search.querySelector('.jodit_search-replace');
var replaceButton = search.querySelector('.jodit_search_buttons-replace');

query.value = 't';
replace.value = 'w';

simulateEvent('click', 0, replaceButton);
simulateEvent('click', 0, replaceButton);
simulateEvent('click', 0, replaceButton);
simulateEvent('click', 0, replaceButton);

expect('wesw wesw test').to.be.equal(editor.getEditorValue());
});
});
});
describe('F3 after search', function () {
it('Should find a next match', function () {

Expand Down

0 comments on commit 5a1ed6f

Please sign in to comment.