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; }