[occur] towards better occur session display
This commit is contained in:
parent
6f68042545
commit
4b0b579bf4
2 changed files with 39 additions and 38 deletions
|
|
@ -74,8 +74,7 @@ oop.inherits(Occur, Search);
|
||||||
this.enter = function(editor, options) {
|
this.enter = function(editor, options) {
|
||||||
if (!options.needle) return false;
|
if (!options.needle) return false;
|
||||||
var pos = editor.getCursorPosition();
|
var pos = editor.getCursorPosition();
|
||||||
editor.setReadOnly(true);
|
this.display(editor, options);
|
||||||
this.display(editor.session, options);
|
|
||||||
var translatedPos = this.originalToOccurPosition(editor.session, pos);
|
var translatedPos = this.originalToOccurPosition(editor.session, pos);
|
||||||
editor.moveCursorToPosition(translatedPos);
|
editor.moveCursorToPosition(translatedPos);
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -94,8 +93,7 @@ oop.inherits(Occur, Search);
|
||||||
var session = editor.session,
|
var session = editor.session,
|
||||||
pos = options.translatePosition && editor.getCursorPosition(),
|
pos = options.translatePosition && editor.getCursorPosition(),
|
||||||
translatedPos = pos && this.occurToOriginalPosition(editor.session, pos);
|
translatedPos = pos && this.occurToOriginalPosition(editor.session, pos);
|
||||||
this.displayOriginal(session);
|
this.displayOriginal(editor);
|
||||||
editor.setReadOnly(false);
|
|
||||||
if (translatedPos) editor.moveCursorToPosition(translatedPos);
|
if (translatedPos) editor.moveCursorToPosition(translatedPos);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -107,22 +105,24 @@ oop.inherits(Occur, Search);
|
||||||
sess._emit("changeBackMarker"); // force highlight layer redraw
|
sess._emit("changeBackMarker"); // force highlight layer redraw
|
||||||
}
|
}
|
||||||
|
|
||||||
this.display = function(session, options) {
|
this.display = function(editor, options) {
|
||||||
this.$originalDoc = session.doc;
|
// this.setSession(session || new EditSession(""))
|
||||||
var found = this.matchingLines(session, options),
|
this.$originalDoc = editor.session.getDocument();
|
||||||
|
var found = this.matchingLines(editor.session, options),
|
||||||
lines = found.map(function(foundLine) { return foundLine.content; }),
|
lines = found.map(function(foundLine) { return foundLine.content; }),
|
||||||
occurDoc = new Document(lines);
|
occurDoc = new Document('');
|
||||||
occurDoc.$occur = this;
|
occurDoc.$occur = this;
|
||||||
occurDoc.$occurMatchingLines = found;
|
occurDoc.$occurMatchingLines = found;
|
||||||
session.setDocument(occurDoc);
|
editor.session.setDocument(occurDoc);
|
||||||
this.highlight(session, options.re);
|
occurDoc.insertLines(0, lines);
|
||||||
session._emit('changeBackMarker');
|
this.highlight(editor.session, options.re);
|
||||||
|
editor.session._emit('changeBackMarker');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.displayOriginal = function(session) {
|
this.displayOriginal = function(editor) {
|
||||||
session.setDocument(this.$originalDoc);
|
editor.session.setDocument(this.$originalDoc);
|
||||||
this.highlight(session, null);
|
this.highlight(editor.session, null);
|
||||||
session._emit('changeBackMarker');
|
editor.session._emit('changeBackMarker');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -42,77 +42,78 @@ var Range = require("./range").Range;
|
||||||
var assert = require("./test/assertions");
|
var assert = require("./test/assertions");
|
||||||
var Occur = require("./occur").Occur;
|
var Occur = require("./occur").Occur;
|
||||||
var occurCommands = require("./commands/occur_commands").commands;
|
var occurCommands = require("./commands/occur_commands").commands;
|
||||||
var editor, occur, session;
|
var editor, occur;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
||||||
name: "ACE occur.js",
|
name: "ACE occur.js",
|
||||||
|
|
||||||
setUp: function() {
|
setUp: function() {
|
||||||
session = new EditSession('');
|
var session = new EditSession('');
|
||||||
editor = new Editor(new MockRenderer(), session);
|
editor = new Editor(new MockRenderer(), session);
|
||||||
occur = new Occur();
|
occur = new Occur();
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: find lines matching" : function() {
|
"test: find lines matching" : function() {
|
||||||
session.doc.insertLines(0, ['abc', 'def', 'xyz', 'bcxbc']);
|
editor.session.insert({row: 0, column: 0}, 'abc\ndef\nxyz\nbcxbc');
|
||||||
var result = occur.matchingLines(session, {needle: 'bc'}),
|
var result = occur.matchingLines(editor.session, {needle: 'bc'}),
|
||||||
expected = [{row: 0, content: 'abc'}, {row: 3, content: 'bcxbc'}];
|
expected = [{row: 0, content: 'abc'}, {row: 3, content: 'bcxbc'}];
|
||||||
assert.deepEqual(result, expected);
|
assert.deepEqual(result, expected);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: display occurrences" : function() {
|
"test: display occurrences" : function() {
|
||||||
var lines = ['abc', 'def', 'xyz', 'bcx'];
|
var text = 'abc\ndef\nxyz\nbcx\n';
|
||||||
session.doc.insertLines(0, lines);
|
editor.session.insert({row: 0, column: 0}, text);
|
||||||
occur.display(session, {needle: 'bc'});
|
occur.display(editor, {needle: 'bc'});
|
||||||
assert.equal(session.getValue(), 'abc\nbcx');
|
assert.equal(editor.getValue(), 'abc\nbcx\n');
|
||||||
occur.displayOriginal(session);
|
occur.displayOriginal(editor);
|
||||||
assert.equal(session.getValue(), lines.join('\n') + '\n');
|
assert.equal(editor.getValue(), text);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: original position from occur doc" : function() {
|
"test: original position from occur doc" : function() {
|
||||||
session.doc.insertLines(0, ['abc', 'def', 'xyz', 'bcx']);
|
var text = 'abc\ndef\nxyz\nbcx\n';
|
||||||
occur.display(session, {needle: 'bc'});
|
editor.session.insert({row: 0, column: 0}, text);
|
||||||
assert.equal(session.getValue(), 'abc\nbcx');
|
occur.display(editor, {needle: 'bc'});
|
||||||
var pos = occur.occurToOriginalPosition(session, {row: 1, column: 2});
|
assert.equal(editor.getValue(), 'abc\nbcx\n');
|
||||||
|
var pos = occur.occurToOriginalPosition(editor.session, {row: 1, column: 2});
|
||||||
assert.position(pos, 3, 2);
|
assert.position(pos, 3, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: occur command" : function() {
|
"test: occur command" : function() {
|
||||||
// setup
|
// setup
|
||||||
var lines = ['hel', 'lo', '', 'wo', 'rld'];
|
var text = 'hel\nlo\n\nwo\nrld\n';
|
||||||
session.doc.insertLines(0, lines);
|
editor.session.insert({row: 0, column: 0}, text);
|
||||||
editor.commands.addCommands(occurCommands);
|
editor.commands.addCommands(occurCommands);
|
||||||
|
|
||||||
// run occur for lines including 'o'
|
// run occur for lines including 'o'
|
||||||
editor.execCommand('occur', {needle: 'o'});
|
editor.execCommand('occur', {needle: 'o'});
|
||||||
assert.equal(session.getValue(), 'lo\nwo');
|
assert.equal(editor.getValue(), 'lo\nwo\n');
|
||||||
|
|
||||||
// command install OK?
|
// command install OK?
|
||||||
assert.ok(editor.getReadOnly(), 'occur doc not marked as read only');
|
// assert.ok(editor.getReadOnly(), 'occur doc not marked as read only');
|
||||||
assert.ok(editor.getKeyboardHandler().isOccurHandler, 'no occur handler installed');
|
assert.ok(editor.getKeyboardHandler().isOccurHandler, 'no occur handler installed');
|
||||||
assert.ok(editor.commands.byName.occurexit, 'no exitoccur command installed');
|
assert.ok(editor.commands.byName.occurexit, 'no exitoccur command installed');
|
||||||
|
|
||||||
// exit occur
|
// exit occur
|
||||||
editor.execCommand('occurexit');
|
editor.execCommand('occurexit');
|
||||||
assert.equal(session.getValue(), lines.join('\n') + '\n');
|
assert.equal(editor.getValue(), text);
|
||||||
|
|
||||||
// editor state cleaned up?
|
// editor state cleaned up?
|
||||||
assert.ok(!editor.getReadOnly(), 'original doc is marked as read only');
|
// assert.ok(!editor.getReadOnly(), 'original doc is marked as read only');
|
||||||
assert.ok(!editor.getKeyboardHandler().isOccurHandler, 'occur handler installed after detach');
|
assert.ok(!editor.getKeyboardHandler().isOccurHandler, 'occur handler installed after detach');
|
||||||
assert.ok(!editor.commands.byName.occurexit, 'exitoccur installed after exiting occur');
|
assert.ok(!editor.commands.byName.occurexit, 'exitoccur installed after exiting occur');
|
||||||
},
|
},
|
||||||
|
|
||||||
"test: occur navigation" : function() {
|
"test: occur navigation" : function() {
|
||||||
// setup
|
// setup
|
||||||
var lines = ['hel', 'lo', '', 'wo', 'rld'];
|
var text = 'hel\nlo\n\nwo\nrld\n';
|
||||||
session.doc.insertLines(0, lines);
|
editor.session.insert({row: 0, column: 0}, text);
|
||||||
editor.commands.addCommands(occurCommands);
|
editor.commands.addCommands(occurCommands);
|
||||||
editor.moveCursorToPosition({row: 1, column: 1});
|
editor.moveCursorToPosition({row: 1, column: 1});
|
||||||
|
|
||||||
// run occur for lines including 'o'
|
// run occur for lines including 'o'
|
||||||
editor.execCommand('occur', {needle: 'o'});
|
editor.execCommand('occur', {needle: 'o'});
|
||||||
assert.equal(session.getValue(), 'lo\nwo');
|
assert.equal(editor.getValue(), 'lo\nwo\n');
|
||||||
assert.position(editor.getCursorPosition(), 0, 1, 'original -> occur pos');
|
assert.position(editor.getCursorPosition(), 0, 1, 'original -> occur pos');
|
||||||
|
|
||||||
// move to second line and accept
|
// move to second line and accept
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue