Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not clear active line and active word markers #604

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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