Simplify some auto completion logic.

square-messages
Black Hat 2018-11-04 12:07:00 +08:00
parent a865aaabb1
commit c19f49a898
2 changed files with 5 additions and 11 deletions

View File

@ -1,16 +1,15 @@
import QtQuick 2.9
RoomPanelForm {
roomHeader.onClicked: roomDrawer.open()
roomHeader.image: spectralController.safeImage(currentRoom ? currentRoom.avatar : null)
roomHeader.topic: currentRoom ? (currentRoom.topic).replace(/(\r\n\t|\n|\r\t)/gm,"") : ""
roomHeader.onClicked: roomDrawer.open()
sortedMessageEventModel.onModelReset: {
if (currentRoom) {
var lastScrollPosition = sortedMessageEventModel.mapFromSource(currentRoom.savedTopVisibleIndex())
console.log("Scrolling to position", lastScrollPosition)
messageListView.currentIndex = lastScrollPosition
if (messageListView.contentY < messageListView.originY + 10 || messageListView.contentHeight < messageListView.height || currentRoom.timelineSize === 0)
if (messageListView.contentY < messageListView.originY + 10 || currentRoom.timelineSize < 20)
currentRoom.getPreviousContent(100)
}
}

View File

@ -51,6 +51,7 @@ Rectangle {
clip: true
orientation: ListView.Horizontal
highlightFollowsCurrentItem: true
keyNavigationWraps: true
highlight: Rectangle {
color: Material.accent
@ -205,17 +206,11 @@ Rectangle {
}
}
Keys.onBacktabPressed: {
if (isAutoCompleting) {
if (autoCompleteListView.currentIndex == 0) autoCompleteListView.currentIndex = autoCompleteListView.count - 1
else autoCompleteListView.currentIndex--
}
}
Keys.onBacktabPressed: if (isAutoCompleting) autoCompleteListView.decrementCurrentIndex()
Keys.onTabPressed: {
if (isAutoCompleting) {
if (autoCompleteListView.currentIndex + 1 == autoCompleteListView.count) autoCompleteListView.currentIndex = 0
else autoCompleteListView.currentIndex++
autoCompleteListView.incrementCurrentIndex()
} else {
autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1
var autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop()