From 27241c505b32c7b5696c17452e3fd9db08c076fe Mon Sep 17 00:00:00 2001 From: taynpg Date: Tue, 21 Jan 2025 12:57:54 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=B0=9D=E8=AF=95=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=B2=98=E8=B4=B4=E4=B8=80=E4=B8=AA=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=AF=BC=E8=87=B4=E7=9A=84=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=8D=A1=E9=A1=BF=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- filecomplete.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/filecomplete.cpp b/filecomplete.cpp index e656e3b..82ec7ee 100644 --- a/filecomplete.cpp +++ b/filecomplete.cpp @@ -497,6 +497,10 @@ char* fc_readline() ++len; }; + bool need_predic = true; + std::chrono::time_point p1, p2; + p1 = std::chrono::high_resolution_clock::now(); + while (1) { word.clear(); clear_line(); @@ -521,10 +525,19 @@ char* fc_readline() } #endif set_cursor_x(cur_pos + 1); + need_predic = true; // Read character from console int ch = _getch(); + p2 = p1; + p1 = std::chrono::high_resolution_clock::now(); + + auto duration = std::chrono::duration_cast(p1 - p2).count(); + if (duration <= 10) { + need_predic = false; + } + switch (ch) { case ENTER: append_his(main_buf); @@ -624,7 +637,12 @@ char* fc_readline() } // 补正 trans2buf(tmp_buf); - str_predict = file_predict(tmp_buf); + if (need_predic) { + str_predict = file_predict(tmp_buf); + } else if (!str_predict.empty()) { + str_predict.clear(); + } + p1 = std::chrono::high_resolution_clock::now(); } return main_buf; }