Commit 2c0e7eb0 authored by fitermay's avatar fitermay Committed by Elizaveta Shashkova
Browse files

PY-26413: More intuitive caret positioning on prev

parent c25531e7
Branches unavailable Tags unavailable
No related merge requests found
Showing with 31 additions and 15 deletions
+31 -15
......@@ -30,11 +30,11 @@ import gnu.trove.TIntStack
*/
private val MasterModels = ConcurrentFactoryMap.createMap<String, MasterModel>(
{
MasterModel()
}, {
ContainerUtil.createConcurrentWeakValueMap()
})
{
MasterModel()
}, {
ContainerUtil.createConcurrentWeakValueMap()
})
private fun assertDispatchThread() = ApplicationManager.getApplication().assertIsDispatchThread()
......@@ -53,7 +53,7 @@ fun createModel(persistenceId: String, console: LanguageConsoleView): ConsoleHis
private class PrefixHistoryModel constructor(private val masterModel: MasterModel,
private val getPrefixFn: () -> String) : ConsoleHistoryBaseModel by masterModel,
ConsoleHistoryModel {
ConsoleHistoryModel {
var userContent: String = ""
override fun setContent(userContent: String) {
......@@ -119,23 +119,26 @@ private class PrefixHistoryModel constructor(private val masterModel: MasterMode
override fun getHistoryPrev(): Entry? {
val entries = myEntries ?: return null
val currentPrefix = getPrefixFn()
if (myPrevEntries.size() > 0) {
myCurrentIndex = myPrevEntries.pop()
return entries[myCurrentIndex].let { Entry(it, -1) }
return createPrevEntry(entries[myCurrentIndex], currentPrefix)
}
else {
resetIndex()
return Entry(userContent, -1)
return createPrevEntry(userContent, currentPrefix)
}
}
private fun createPrevEntry(prevEntry: String, currentPrefix: String): Entry = if (prevEntry.startsWith(currentPrefix)) Entry(prevEntry, currentPrefix.length) else Entry(prevEntry, 0)
override fun getCurrentIndex(): Int =
if (myCurrentIndex != -1) {
myCurrentIndex
}
else {
entries.size - 1
}
if (myCurrentIndex != -1) {
myCurrentIndex
}
else {
entries.size - 1
}
override fun prevOnLastLine(): Boolean = true
......
......@@ -96,8 +96,21 @@ public class ConsoleHistoryConstrollerTest extends LightPlatformCodeInsightTestC
execStatementList1();
setCaretWithText("Statement<caret> 4");
consoleNext();
consoleNext();
consolePrev();
checkResultByText("Statement<caret> 4");
}
//PY-26413
public void testNavigateDown2() {
execStatementList1();
setCaretWithText("<caret>Statement 4");
consoleNext();
consoleNext();
setCaretWithText("Statement<caret> 3");
consolePrev();
checkResultByText("Statement 4<caret>");
checkResultByText("<caret>Different Prefix");
}
public void testNavigateUpNoPrefix() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment