:recycle: [Refactor] Merge scroll to bottom functions to ScreenScroller
Browse files- components/buttons_binder.js +6 -6
- components/chat_operator.js +3 -28
- storage/states.js +34 -0
components/buttons_binder.js
CHANGED
@@ -4,10 +4,10 @@ import {
|
|
4 |
start_latest_message_animation,
|
5 |
create_new_chat_session,
|
6 |
get_latest_message_content_displayer,
|
7 |
-
scroll_to_bottom,
|
8 |
-
set_user_scroll_status,
|
9 |
} from "./chat_operator.js";
|
10 |
|
|
|
|
|
11 |
export class ButtonsBinder {
|
12 |
constructor() {}
|
13 |
bind() {
|
@@ -100,7 +100,7 @@ class SendUserInputButtonBinder {
|
|
100 |
.addClass("icon-success");
|
101 |
hljs.highlightAll();
|
102 |
console.log(get_latest_message_content_displayer().data("raw_content"));
|
103 |
-
|
104 |
}
|
105 |
}
|
106 |
|
@@ -183,8 +183,8 @@ class ScrollToBottomButtonBinder {
|
|
183 |
const button = $("#scroll-to-bottom-button");
|
184 |
button.attr("title", "Scroll to bottom");
|
185 |
button.click(() => {
|
186 |
-
|
187 |
-
scroll_to_bottom(true);
|
188 |
});
|
189 |
}
|
190 |
}
|
@@ -194,7 +194,7 @@ class ChatSessionContainerScrollBinder {
|
|
194 |
bind() {
|
195 |
$("#chat-session-container").on("wheel touchmove", function () {
|
196 |
if ($("#send-user-input").attr("status") === "stop") {
|
197 |
-
|
198 |
}
|
199 |
});
|
200 |
}
|
|
|
4 |
start_latest_message_animation,
|
5 |
create_new_chat_session,
|
6 |
get_latest_message_content_displayer,
|
|
|
|
|
7 |
} from "./chat_operator.js";
|
8 |
|
9 |
+
import { screen_scroller } from "../storage/states.js";
|
10 |
+
|
11 |
export class ButtonsBinder {
|
12 |
constructor() {}
|
13 |
bind() {
|
|
|
100 |
.addClass("icon-success");
|
101 |
hljs.highlightAll();
|
102 |
console.log(get_latest_message_content_displayer().data("raw_content"));
|
103 |
+
screen_scroller.set_user_scrolling(false);
|
104 |
}
|
105 |
}
|
106 |
|
|
|
183 |
const button = $("#scroll-to-bottom-button");
|
184 |
button.attr("title", "Scroll to bottom");
|
185 |
button.click(() => {
|
186 |
+
screen_scroller.set_user_scrolling(false);
|
187 |
+
screen_scroller.scroll_to_bottom(true);
|
188 |
});
|
189 |
}
|
190 |
}
|
|
|
194 |
bind() {
|
195 |
$("#chat-session-container").on("wheel touchmove", function () {
|
196 |
if ($("#send-user-input").attr("status") === "stop") {
|
197 |
+
screen_scroller.set_user_scrolling(true);
|
198 |
}
|
199 |
});
|
200 |
}
|
components/chat_operator.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import { Messager, MessagerList } from "./messager.js";
|
2 |
import { transform_footnote } from "../converters/stream_jsonizer.js";
|
|
|
3 |
|
4 |
let messagers_container = $("#messagers-container");
|
5 |
let available_models_select = $("#available-models-select");
|
@@ -10,32 +11,6 @@ let chat_history = [messager_list];
|
|
10 |
let md_to_html_converter = new showdown.Converter();
|
11 |
md_to_html_converter.setFlavor("github");
|
12 |
|
13 |
-
let is_user_scrolling = false;
|
14 |
-
|
15 |
-
export function set_user_scroll_status(val = true) {
|
16 |
-
is_user_scrolling = val;
|
17 |
-
}
|
18 |
-
|
19 |
-
export function scroll_to_bottom(animate = false) {
|
20 |
-
if (is_user_scrolling) {
|
21 |
-
return;
|
22 |
-
}
|
23 |
-
console.log("scroll_to_bottom");
|
24 |
-
if (animate) {
|
25 |
-
$("#chat-session-container").animate(
|
26 |
-
{
|
27 |
-
scrollTop: $("#chat-session-container").prop("scrollHeight"),
|
28 |
-
},
|
29 |
-
500
|
30 |
-
);
|
31 |
-
} else {
|
32 |
-
$("#chat-session-container").prop(
|
33 |
-
"scrollTop",
|
34 |
-
$("#chat-session-container").prop("scrollHeight")
|
35 |
-
);
|
36 |
-
}
|
37 |
-
}
|
38 |
-
|
39 |
export function get_active_messager_list() {
|
40 |
return chat_history[chat_history.length - 1];
|
41 |
}
|
@@ -58,7 +33,7 @@ export function create_messager(
|
|
58 |
};
|
59 |
let messager = new Messager(message);
|
60 |
get_active_messager_list().push(messager);
|
61 |
-
scroll_to_bottom();
|
62 |
}
|
63 |
|
64 |
export function get_selected_llm_model() {
|
@@ -142,7 +117,7 @@ export function update_message(json_chunks, content_displayer = null) {
|
|
142 |
content_displayer
|
143 |
.find("table")
|
144 |
.addClass("table table-bordered table-hover");
|
145 |
-
scroll_to_bottom();
|
146 |
}
|
147 |
if (finish_reason === "stop") {
|
148 |
console.log("[STOP]");
|
|
|
1 |
import { Messager, MessagerList } from "./messager.js";
|
2 |
import { transform_footnote } from "../converters/stream_jsonizer.js";
|
3 |
+
import { screen_scroller } from "../storage/states.js";
|
4 |
|
5 |
let messagers_container = $("#messagers-container");
|
6 |
let available_models_select = $("#available-models-select");
|
|
|
11 |
let md_to_html_converter = new showdown.Converter();
|
12 |
md_to_html_converter.setFlavor("github");
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
export function get_active_messager_list() {
|
15 |
return chat_history[chat_history.length - 1];
|
16 |
}
|
|
|
33 |
};
|
34 |
let messager = new Messager(message);
|
35 |
get_active_messager_list().push(messager);
|
36 |
+
screen_scroller.scroll_to_bottom();
|
37 |
}
|
38 |
|
39 |
export function get_selected_llm_model() {
|
|
|
117 |
content_displayer
|
118 |
.find("table")
|
119 |
.addClass("table table-bordered table-hover");
|
120 |
+
screen_scroller.scroll_to_bottom();
|
121 |
}
|
122 |
if (finish_reason === "stop") {
|
123 |
console.log("[STOP]");
|
storage/states.js
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class ScreenScroller {
|
2 |
+
constructor() {
|
3 |
+
this.is_user_scrolling = false;
|
4 |
+
}
|
5 |
+
get_user_scrolling() {
|
6 |
+
return this.is_user_scrolling;
|
7 |
+
}
|
8 |
+
set_user_scrolling(val = true) {
|
9 |
+
this.is_user_scrolling = val;
|
10 |
+
}
|
11 |
+
scroll_to_bottom(animate = false) {
|
12 |
+
if (this.get_user_scrolling()) {
|
13 |
+
return;
|
14 |
+
}
|
15 |
+
console.log("scroll_to_bottom");
|
16 |
+
if (animate) {
|
17 |
+
$("#chat-session-container").animate(
|
18 |
+
{
|
19 |
+
scrollTop: $("#chat-session-container").prop(
|
20 |
+
"scrollHeight"
|
21 |
+
),
|
22 |
+
},
|
23 |
+
500
|
24 |
+
);
|
25 |
+
} else {
|
26 |
+
$("#chat-session-container").prop(
|
27 |
+
"scrollTop",
|
28 |
+
$("#chat-session-container").prop("scrollHeight")
|
29 |
+
);
|
30 |
+
}
|
31 |
+
}
|
32 |
+
}
|
33 |
+
|
34 |
+
export let screen_scroller = new ScreenScroller();
|