Skip to content

Commit

Permalink
Do not clear active line and active word markers (#604)
Browse files Browse the repository at this point in the history
  • Loading branch information
hansbugge authored and securingsincity committed Mar 11, 2019
1 parent 2526dfd commit 7b0b7e2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/ace.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,14 @@ export default class ReactAce extends Component {
this.editor.getSession().removeMarker(currentMarkers[i].id);
}
}
// remove background markers
// remove background markers except active line marker and selected word marker
currentMarkers = this.editor.getSession().getMarkers(false);
for (const i in currentMarkers) {
if (currentMarkers.hasOwnProperty(i)) {
if (
currentMarkers.hasOwnProperty(i) &&
currentMarkers[i].clazz !== "ace_active-line" &&
currentMarkers[i].clazz !== "ace_selected-word"
) {
this.editor.getSession().removeMarker(currentMarkers[i].id);
}
}
Expand Down
30 changes: 29 additions & 1 deletion tests/src/ace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,40 @@ describe('Ace Component', () => {

// Read the markers
const editor = wrapper.instance().editor;
expect(Object.keys(editor.getSession().getMarkers())).to.deep.equal(['1', '2', '3']);
expect(editor.getSession().getMarkers()['3'].clazz).to.equal('test-marker-old');
expect(editor.getSession().getMarkers()['3'].type).to.equal('text');
wrapper.setProps({markers});
const editorB = wrapper.instance().editor;

expect(editorB.getSession().getMarkers()).to.deep.equal({})
expect(Object.keys(editorB.getSession().getMarkers())).to.deep.equal(['1', '2']);
});

it('should not remove active line and selected word highlight when clearing markers', () => {
const newMarkers = [
{
startRow: 4,
type: 'text',
className: 'test-marker'
}
];
const wrapper = mount(
<AceEditor highlightActiveLine markers={[]} />,
mountOptions
);

const editor = wrapper.instance().editor;
const bgMarkers = editor.getSession().getMarkers(false);
expect(Object.keys(bgMarkers)).to.deep.equal(['1', '2']);
expect(bgMarkers['1']).to.have.property('clazz', 'ace_active-line');
expect(bgMarkers['2']).to.have.property('clazz', 'ace_selected-word');

wrapper.setProps({ markers: newMarkers });
const bgMarkersNew = editor.getSession().getMarkers(false);
expect(Object.keys(bgMarkersNew)).to.deep.equal(['1', '2', '3']);
expect(bgMarkersNew['1']).to.have.property('clazz', 'ace_active-line');
expect(bgMarkersNew['2']).to.have.property('clazz', 'ace_selected-word');
expect(bgMarkersNew['3']).to.have.property('clazz', 'test-marker');
});

it('should add annotations and clear them', () => {
Expand Down

0 comments on commit 7b0b7e2

Please sign in to comment.