Skip to content

Commit d5bac10

Browse files
committed
Merge branch 'dev'
2 parents c1e86f0 + edb22f6 commit d5bac10

File tree

14 files changed

+222
-102
lines changed

14 files changed

+222
-102
lines changed

flymoon/src/logic/chat_session.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ fn pretty_mcp_tool_sep(ui: Weak<AppWindow>, tool_list: Vec<String>) {
895895

896896
entry.bot = entry
897897
.bot
898-
.replace(MCP_TOOL_START_SEP, "```")
899-
.replace(MCP_TOOL_END_SEP, "```")
898+
.replace(MCP_TOOL_START_SEP, "\n```")
899+
// .replace(MCP_TOOL_END_SEP, "```")
900900
.into();
901901

902902
store_current_chat_session_histories!(ui).set_row_data(last_index, entry);

flymoon/src/logic/md.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
use crate::slint_generatedAppWindow::{
2-
AppWindow, ChatEntry as UIChatEntry, Logic, MdElement as UIMdElement,
3-
MdElementType as UIMdElementType, MdHeading as UIMdHeading, MdImage as UIMdImage,
4-
MdListItem as UIMdListItem, MdMath as UIMdMath, MdTable as UIMdTable, MdUrl as UIMdUrl, Store,
2+
AppWindow, ChatEntry as UIChatEntry, Logic, MdCodeBlock as UIMdCodeBlock,
3+
MdElement as UIMdElement, MdElementType as UIMdElementType, MdHeading as UIMdHeading,
4+
MdImage as UIMdImage, MdListItem as UIMdListItem, MdMath as UIMdMath, MdTable as UIMdTable,
5+
MdUrl as UIMdUrl, Store,
56
};
67
use crate::{config::cache_dir, store_current_chat_session_histories};
78
use cutil::{crypto, http};
8-
use dummy_markdown::{self, MdElement, MdElementType, MdHeading, MdListItem, MdTable, MdUrl};
9+
use dummy_markdown::{
10+
self, MdCodeBlock, MdElement, MdElementType, MdHeading, MdListItem, MdTable, MdUrl,
11+
};
912
use once_cell::sync::Lazy;
1013
use once_cell::sync::OnceCell;
1114
use slint::{ComponentHandle, Image, Model, ModelRc, SharedString, VecModel, Weak};
@@ -101,6 +104,15 @@ impl From<String> for UIMdImage {
101104
}
102105
}
103106

107+
impl From<MdCodeBlock> for UIMdCodeBlock {
108+
fn from(code_block: MdCodeBlock) -> Self {
109+
UIMdCodeBlock {
110+
lang: code_block.lang.into(),
111+
code: code_block.code.trim().into(),
112+
}
113+
}
114+
}
115+
104116
impl From<MdTable> for UIMdTable {
105117
fn from(table: MdTable) -> Self {
106118
UIMdTable {
@@ -135,7 +147,7 @@ impl From<MdElement> for UIMdElement {
135147
ty: entry.ty.into(),
136148
text: entry.text.into(),
137149
math: entry.math.into(),
138-
code_block: entry.code_block.trim().to_string().into(),
150+
code_block: entry.code_block.into(),
139151
list_item: entry.list_item.into(),
140152
img: entry.image_url.into(),
141153
heading: entry.heading.into(),

flymoon/src/logic/tr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ pub fn tr(text: &str) -> String {
250250
),
251251
("Increase font size", "增大字体"),
252252
("Decrease font size", "缩小字体"),
253+
("Focus question input box", "输入框获取输入焦点"),
253254
]);
254255

255256
if let Some(txt) = items.get(text) {

flymoon/src/version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pub static VERSION: &str = "v0.1.8";
1+
pub static VERSION: &str = "v0.1.9";

flymoon/ui/base/skeleton.slint

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export enum SkeletonType {
1515
component InnerItem inherits Rectangle {
1616
in-out property <color> active-item-color: Theme.base-background;
1717
in-out property <bool> enabled-active: true;
18-
in-out property <float> active-opacity: 0.2;
18+
in-out property <float> active-opacity: 0.4;
1919
in-out property <duration> active-duration: 500ms;
2020

2121
width: root.width * 80%;
@@ -39,8 +39,8 @@ export component Skeleton inherits Rectangle {
3939
in-out property <color> item-color: Theme.is-dark ? Theme.secondary-background.darker(5%) : Theme.secondary-background.darker(5%);
4040

4141
in-out property <bool> enabled-active: true;
42-
in-out property <color> active-item-color: self.item-color.brighter(20%);
43-
in-out property <float> active-opacity: 0.2;
42+
in-out property <color> active-item-color: self.item-color.brighter(50%);
43+
in-out property <float> active-opacity: 0.4;
4444
in-out property <duration> active-duration: 800ms;
4545

4646
pure public function from-number(index: int) -> SkeletonType {

flymoon/ui/panel/desktop/chat/input.slint

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ export component Input inherits Rectangle {
1515
height: 130px;
1616
forward-focus: te;
1717

18+
function update-height(height: length) {
19+
root.height = Math.clamp(height, 130px, Theme.default-height / 3 * 2);
20+
}
21+
1822
function ensure-show-cursor() {
1923
if (flick.viewport-height <= flick.height) {
2024
flick.viewport-y = 0;
@@ -69,6 +73,10 @@ export component Input inherits Rectangle {
6973
flick := Flickable {
7074
y: Theme.padding * 2;
7175

76+
changed viewport-height => {
77+
root.update-height(self.viewport-height + h-btns.preferred-height);
78+
}
79+
7280
VerticalLayout {
7381
padding: Theme.padding * 2;
7482

@@ -170,7 +178,7 @@ export component Input inherits Rectangle {
170178
}
171179
}
172180

173-
HorizontalLayout {
181+
h-btns := HorizontalLayout {
174182
height: Theme.icon-size * 2;
175183
alignment: LayoutAlignment.space-between;
176184

flymoon/ui/panel/desktop/chat/md.slint

Lines changed: 70 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { Theme, Store, Logic, Icons, Util } from "../../def.slint";
2-
import { ChatEntry, MdElementType, MdImage, MdMath, MdElement, MdUrl, MdHeading, MdUrl, MdListItem, MdTable } from "../../../store.slint";
2+
import { ChatEntry, MdElementType, MdImage, MdMath, MdElement, MdUrl, MdHeading, MdUrl, MdListItem, MdTable, MdCodeBlock } from "../../../store.slint";
33
import { IconBtn, Label, Link, ToolTipSetting, ComponentPosition } from "../../../base/widgets.slint";
44
import { SearchLink } from "../../../store.slint";
5+
import { ScrollView } from "std-widgets.slint";
56

67
export component MdText inherits HorizontalLayout {
78
in-out property text <=> txt.text;
@@ -66,7 +67,7 @@ component MdListItem inherits HorizontalLayout {
6667
}
6768

6869
export component MdCodeBlock inherits HorizontalLayout {
69-
in-out property <string> code;
70+
in-out property <MdCodeBlock> code-block;
7071

7172
padding-bottom: Theme.padding * 4;
7273

@@ -79,39 +80,83 @@ export component MdCodeBlock inherits HorizontalLayout {
7980
background: Theme.code-header-color;
8081

8182
HorizontalLayout {
82-
alignment: LayoutAlignment.end;
83+
alignment: LayoutAlignment.space-between;
8384
padding: Theme.padding * 2;
8485
padding-right: Theme.padding * 3;
86+
padding-left: Theme.padding * 4;
8587

86-
IconBtn {
87-
icon: Icons.copy;
88-
tip: Logic.tr("copy");
89-
is-show-tip: true;
90-
gain-focus-when-clicked: false;
88+
Label {
89+
text: code-block.lang;
90+
}
91+
92+
HorizontalLayout {
93+
spacing: Theme.spacing * 4;
94+
95+
IconBtn {
96+
icon: Icons.copy;
97+
tip: Logic.tr("copy");
98+
is-show-tip: true;
99+
gain-focus-when-clicked: false;
91100

92-
clicked => {
93-
Logic.copy-to-clipboard(code);
101+
clicked => {
102+
Logic.copy-to-clipboard(code-block.code);
103+
}
94104
}
95105
}
96106
}
97107
}
98108

109+
// `ScrollView` could catch scroll event. However, short content should not catch scroll event
99110
Rectangle {
100-
border-bottom-left-radius: Theme.border-radius;
101-
border-bottom-right-radius: Theme.border-radius;
102-
background: Theme.thirdly-background;
111+
private property <float> rate: 0.5;
112+
private property <bool> use-scrollview: txt-rect.preferred-height > (Theme.default-height * rate);
103113

104-
HorizontalLayout {
105-
padding: Theme.padding * 4;
106-
padding-top: Theme.padding * 2;
107-
108-
txt := TextInput {
109-
wrap: word-wrap;
110-
color: Theme.primary-text-color;
111-
font-size: Theme.title4-font-size;
112-
single-line: false;
113-
read-only: true;
114-
text: code;
114+
height: use-scrollview ? Theme.default-height * rate : txt-rect.preferred-height;
115+
116+
Rectangle {
117+
visible: !use-scrollview;
118+
border-bottom-left-radius: Theme.border-radius;
119+
border-bottom-right-radius: Theme.border-radius;
120+
background: Theme.thirdly-background;
121+
122+
HorizontalLayout {
123+
padding: Theme.padding * 4;
124+
padding-top: Theme.padding * 2;
125+
126+
TextInput {
127+
wrap: word-wrap;
128+
color: Theme.primary-text-color;
129+
font-size: Theme.title4-font-size;
130+
single-line: false;
131+
read-only: true;
132+
text: code-block.code;
133+
}
134+
}
135+
}
136+
137+
ScrollView {
138+
visible: use-scrollview;
139+
viewport-height: txt-rect.preferred-height;
140+
height: Math.min(txt-rect.preferred-height, Theme.default-height * rate);
141+
142+
txt-rect := Rectangle {
143+
border-bottom-left-radius: Theme.border-radius;
144+
border-bottom-right-radius: Theme.border-radius;
145+
background: Theme.thirdly-background;
146+
147+
HorizontalLayout {
148+
padding: Theme.padding * 4;
149+
padding-top: Theme.padding * 2;
150+
151+
txt := TextInput {
152+
wrap: word-wrap;
153+
color: Theme.primary-text-color;
154+
font-size: Theme.title4-font-size;
155+
single-line: false;
156+
read-only: true;
157+
text: code-block.code;
158+
}
159+
}
115160
}
116161
}
117162
}
@@ -284,7 +329,7 @@ export component MdDetail inherits Rectangle {
284329
}
285330

286331
if entry.ty == MdElementType.CodeBlock: MdCodeBlock {
287-
code: entry.code_block;
332+
code-block: entry.code-block;
288333
}
289334

290335
if entry.ty == MdElementType.Math: MdMath {

flymoon/ui/panel/desktop/chat/panel.slint

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ export component Chat inherits VerticalLayout {
1313
spacing: Theme.spacing * 2;
1414

1515
Rectangle {
16-
session := Session { }
16+
session := Session {
17+
focus-input => {
18+
input.focus();
19+
}
20+
}
1721

1822
if Store.input-prompt-list-entries.length > 0: InputPromptList {
1923
x: 0;

0 commit comments

Comments
 (0)