mirror of
https://github.com/RustyRaptor/brackets.git
synced 2026-12-04 00:15:22 -07:00
insert hint without replacing text to the right of the caret
This commit is contained in:
1 parent
8e2b60dcf1
commit
69410b1ac1
2 files changed
+15
-39
No files matched your search
@@ -464,35 +464,9 @@ define(function (require, exports, module) {
|
||||
token = session.getToken(cursor),
|
||||
query = session.getQuery(),
|
||||
start = {line: cursor.line, ch: cursor.ch - query.length},
|
||||
end = {line: cursor.line, ch: (token ? token.end : cursor.ch)},
|
||||
end = {line: cursor.line, ch: cursor.ch},
|
||||
delimiter;
|
||||
|
||||
if (token && token.string === ".") {
|
||||
var nextToken = session.getNextTokenOnLine(cursor);
|
||||
|
||||
if (nextToken && // don't replace delimiters, etc.
|
||||
HintUtils.maybeIdentifier(nextToken.string) &&
|
||||
HintUtils.hintable(nextToken)) {
|
||||
end.ch = nextToken.end;
|
||||
}
|
||||
}
|
||||
|
||||
// If the hint is a string literal, choose a delimiter in which
|
||||
// to wrap it, preserving the existing delimiter if possible.
|
||||
if (hint.literal && hint.kind === "string") {
|
||||
if (token.string.indexOf(HintUtils.DOUBLE_QUOTE) === 0) {
|
||||
delimiter = HintUtils.DOUBLE_QUOTE;
|
||||
} else if (token.string.indexOf(HintUtils.SINGLE_QUOTE) === 0) {
|
||||
delimiter = HintUtils.SINGLE_QUOTE;
|
||||
} else {
|
||||
delimiter = hint.delimiter;
|
||||
}
|
||||
|
||||
completion = completion.replace("\\", "\\\\");
|
||||
completion = completion.replace(delimiter, "\\" + delimiter);
|
||||
completion = delimiter + completion + delimiter;
|
||||
}
|
||||
|
||||
if (session.getType().showFunctionType) {
|
||||
// function types show up as hints, so don't insert anything
|
||||
// if we were displaying a function type
|
||||
|
||||
@@ -637,10 +637,11 @@ define(function (require, exports, module) {
|
||||
});
|
||||
});
|
||||
|
||||
it("should replace property hints with no current query", function () {
|
||||
it("should insert, not replace, property hints with no current query", function () {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 3 },
|
||||
end = { line: 6, ch: 8 };
|
||||
end = { line: 6, ch: 8 },
|
||||
endplus = { line: 6, ch: 12 };
|
||||
|
||||
testDoc.replaceRange("A1.prop", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
@@ -649,12 +650,12 @@ define(function (require, exports, module) {
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(8);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("A1.propAprop");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(12);
|
||||
});
|
||||
});
|
||||
|
||||
it("should replace property hints with a partial current query", function () {
|
||||
it("should insert, not replace, property hints with a partial current query", function () {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 6 },
|
||||
end = { line: 6, ch: 8 };
|
||||
@@ -673,16 +674,17 @@ define(function (require, exports, module) {
|
||||
it("should replace property hints replacing a partial current query", function () {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 6 },
|
||||
end = { line: 6, ch: 8 };
|
||||
|
||||
end = { line: 6, ch: 8 },
|
||||
endplus = { line: 6, ch: 10 };
|
||||
|
||||
testDoc.replaceRange("A1.propB", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
var hintObj = expectHints(JSCodeHints.jsHintProvider);
|
||||
selectHint(JSCodeHints.jsHintProvider, hintObj, "propA");
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, end)).toEqual("A1.propA");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(8);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("A1.propApB");
|
||||
expect(testDoc.getLine(end.line).length).toEqual(10);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -690,7 +692,7 @@ define(function (require, exports, module) {
|
||||
var start = { line: 6, ch: 0 },
|
||||
middle = { line: 6, ch: 4 },
|
||||
end = { line: 6, ch: 9 },
|
||||
endplus = { line: 6, ch: 10 };
|
||||
endplus = { line: 6, ch: 14 };
|
||||
|
||||
testDoc.replaceRange("(A1.prop)", start, start);
|
||||
testEditor.setCursorPos(middle);
|
||||
@@ -699,8 +701,8 @@ define(function (require, exports, module) {
|
||||
|
||||
runs(function () {
|
||||
expect(testEditor.getCursorPos()).toEqual(end);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propA)");
|
||||
expect(testDoc.getLine(endplus.line).length).toEqual(10);
|
||||
expect(testDoc.getRange(start, endplus)).toEqual("(A1.propAprop)");
|
||||
expect(testDoc.getLine(endplus.line).length).toEqual(14);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user