Improve the code for completions
This commit is contained in:
@@ -16,7 +16,7 @@ KirigamiComponents.ConvergentContextMenu {
|
|||||||
id: root
|
id: root
|
||||||
|
|
||||||
required property Kirigami.ApplicationWindow window
|
required property Kirigami.ApplicationWindow window
|
||||||
required property var author
|
required property NeochatRoomMember author
|
||||||
|
|
||||||
headerContentItem: RowLayout {
|
headerContentItem: RowLayout {
|
||||||
id: detailRow
|
id: detailRow
|
||||||
|
|||||||
@@ -61,9 +61,9 @@ Item {
|
|||||||
target: root.currentRoom.mainCache
|
target: root.currentRoom.mainCache
|
||||||
|
|
||||||
function onMentionAdded(text: string, hRef: string): void {
|
function onMentionAdded(text: string, hRef: string): void {
|
||||||
completionMenu.complete(text, hRef);
|
core.completionModel.insertCompletion(text, hRef);
|
||||||
// move the focus back to the chat bar
|
// move the focus back to the chat bar
|
||||||
contentModel.refocusCurrentComponent();
|
core.model.refocusCurrentComponent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,9 +23,34 @@ QQC2.Control {
|
|||||||
|
|
||||||
required property real maxAvailableWidth
|
required property real maxAvailableWidth
|
||||||
|
|
||||||
Message.contentModel: contentModel
|
readonly property ChatBarMessageContentModel model: ChatBarMessageContentModel {
|
||||||
|
type: root.chatBarType
|
||||||
|
room: root.room
|
||||||
|
sendMessageWithEnter: NeoChatConfig.sendMessageWith === 0
|
||||||
|
}
|
||||||
|
|
||||||
onActiveFocusChanged: contentModel.refocusCurrentComponent()
|
readonly property LibNeoChat.CompletionModel completionModel: LibNeoChat.CompletionModel {
|
||||||
|
room: root.room
|
||||||
|
type: root.chatBarType
|
||||||
|
textItem: root.model.focusedTextItem
|
||||||
|
roomListModel: RoomManager.roomListModel
|
||||||
|
userListModel: RoomManager.userListModel
|
||||||
|
|
||||||
|
onIsCompletingChanged: {
|
||||||
|
if (!isCompleting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let dialog = Qt.createComponent('org.kde.neochat.chatbar', 'CompletionMenu').createObject(root.model.focusedTextItem.textItem, {
|
||||||
|
model: root.completionModel,
|
||||||
|
keyHelper: root.model.keyHelper
|
||||||
|
}).open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Message.contentModel: root.model
|
||||||
|
|
||||||
|
onActiveFocusChanged: root.model.refocusCurrentComponent()
|
||||||
|
|
||||||
implicitWidth: root.maxAvailableWidth - (root.maxAvailableWidth >= (parent?.width ?? 0) ? Kirigami.Units.largeSpacing * 2 : 0)
|
implicitWidth: root.maxAvailableWidth - (root.maxAvailableWidth >= (parent?.width ?? 0) ? Kirigami.Units.largeSpacing * 2 : 0)
|
||||||
topPadding: Kirigami.Units.smallSpacing
|
topPadding: Kirigami.Units.smallSpacing
|
||||||
@@ -38,9 +63,9 @@ QQC2.Control {
|
|||||||
maxAvailableWidth: root.maxAvailableWidth - Kirigami.Units.largeSpacing * 2
|
maxAvailableWidth: root.maxAvailableWidth - Kirigami.Units.largeSpacing * 2
|
||||||
|
|
||||||
room: root.room
|
room: root.room
|
||||||
contentModel: chatContentView.model
|
contentModel: root.model
|
||||||
|
|
||||||
onClicked: contentModel.refocusCurrentComponent()
|
onClicked: root.model.refocusCurrentComponent()
|
||||||
}
|
}
|
||||||
Kirigami.Separator {
|
Kirigami.Separator {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
@@ -58,7 +83,7 @@ QQC2.Control {
|
|||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
readonly property real visibleTop: chatScrollView.QQC2.ScrollBar.vertical.position * chatScrollView.contentHeight
|
readonly property real visibleTop: chatScrollView.QQC2.ScrollBar.vertical.position * chatScrollView.contentHeight
|
||||||
readonly property real visibleBottom: chatScrollView.QQC2.ScrollBar.vertical.position * chatScrollView.contentHeight + chatScrollView.QQC2.ScrollBar.vertical.size * chatScrollView.contentHeight
|
readonly property real visibleBottom: chatScrollView.QQC2.ScrollBar.vertical.position * chatScrollView.contentHeight + chatScrollView.QQC2.ScrollBar.vertical.size * chatScrollView.contentHeight
|
||||||
readonly property rect cursorRectInColumn: mapFromItem(contentModel.focusedTextItem.textItem, contentModel.focusedTextItem.cursorRectangle);
|
readonly property rect cursorRectInColumn: mapFromItem(root.model.focusedTextItem.textItem, root.model.focusedTextItem.cursorRectangle);
|
||||||
onCursorRectInColumnChanged: {
|
onCursorRectInColumnChanged: {
|
||||||
if (chatScrollView.QQC2.ScrollBar.vertical.visible) {
|
if (chatScrollView.QQC2.ScrollBar.vertical.visible) {
|
||||||
if (cursorRectInColumn.y < visibleTop) {
|
if (cursorRectInColumn.y < visibleTop) {
|
||||||
@@ -74,12 +99,7 @@ QQC2.Control {
|
|||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
id: chatContentView
|
id: chatContentView
|
||||||
model: ChatBarMessageContentModel {
|
model: root.model
|
||||||
id: contentModel
|
|
||||||
type: root.chatBarType
|
|
||||||
room: root.room
|
|
||||||
sendMessageWithEnter: NeoChatConfig.sendMessageWith === 0
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate: BaseMessageComponentChooser {
|
delegate: BaseMessageComponentChooser {
|
||||||
rightAnchorMargin: chatScrollView.QQC2.ScrollBar.vertical.visible ? chatScrollView.QQC2.ScrollBar.vertical.width : 0
|
rightAnchorMargin: chatScrollView.QQC2.ScrollBar.vertical.visible ? chatScrollView.QQC2.ScrollBar.vertical.width : 0
|
||||||
@@ -89,7 +109,7 @@ QQC2.Control {
|
|||||||
}
|
}
|
||||||
SendBar {
|
SendBar {
|
||||||
room: root.room
|
room: root.room
|
||||||
contentModel: chatContentView.model
|
contentModel: root.model
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,27 +125,4 @@ QQC2.Control {
|
|||||||
width: 1
|
width: 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QtObject {
|
|
||||||
id: _private
|
|
||||||
|
|
||||||
property LibNeoChat.CompletionModel completionModel: LibNeoChat.CompletionModel {
|
|
||||||
room: root.room
|
|
||||||
type: root.chatBarType
|
|
||||||
textItem: contentModel.focusedTextItem
|
|
||||||
roomListModel: RoomManager.roomListModel
|
|
||||||
userListModel: RoomManager.userListModel
|
|
||||||
|
|
||||||
onIsCompletingChanged: {
|
|
||||||
if (!isCompleting) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let dialog = Qt.createComponent('org.kde.neochat.chatbar', 'CompletionMenu').createObject(contentModel.focusedTextItem.textItem, {
|
|
||||||
model: _private.completionModel,
|
|
||||||
keyHelper: contentModel.keyHelper
|
|
||||||
}).open();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,10 +68,6 @@ QQC2.Popup {
|
|||||||
completions.decrementCurrentIndex();
|
completions.decrementCurrentIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
function complete(text: string, hRef: string) {
|
|
||||||
model.insertCompletion(text, hRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
function completeCurrent() {
|
function completeCurrent() {
|
||||||
model.insertCompletion(completions.currentItem.replacedText, completions.currentItem.hRef);
|
model.insertCompletion(completions.currentItem.replacedText, completions.currentItem.hRef);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,11 +20,12 @@ RowLayout {
|
|||||||
/**
|
/**
|
||||||
* @brief The message author.
|
* @brief The message author.
|
||||||
*
|
*
|
||||||
* A Quotient::RoomMember object.
|
* A NeochatRoomMember object (which is just a QML safe wrapper around
|
||||||
|
* Quotient::RoomMember).
|
||||||
*
|
*
|
||||||
* @sa Quotient::RoomMember
|
* @sa NeochatRoomMember, Quotient::RoomMember
|
||||||
*/
|
*/
|
||||||
required property var author
|
required property NeochatRoomMember author
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The timestamp of the event as a neoChatDateTime.
|
* @brief The timestamp of the event as a neoChatDateTime.
|
||||||
|
|||||||
Reference in New Issue
Block a user