Fixes and cleanup
This commit is contained in:
@@ -105,6 +105,7 @@ struct Editor {
|
||||
std::vector<Highlight> query_map;
|
||||
std::vector<int8_t> folded;
|
||||
Spans spans;
|
||||
Spans def_spans;
|
||||
std::map<uint32_t, bool> folded_node;
|
||||
};
|
||||
|
||||
@@ -128,8 +129,11 @@ void edit_erase(Editor *editor, Coord pos, int64_t len);
|
||||
void edit_insert(Editor *editor, Coord pos, char *data, uint32_t len);
|
||||
Coord editor_hit_test(Editor *editor, uint32_t x, uint32_t y);
|
||||
char *get_selection(Editor *editor, uint32_t *out_len);
|
||||
void editor_worker(Editor *editor);
|
||||
void word_boundaries(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||
uint32_t *next_col, uint32_t *prev_clusters,
|
||||
uint32_t *next_clusters);
|
||||
void word_boundaries_exclusive(Editor *editor, Coord coord, uint32_t *prev_col,
|
||||
uint32_t *next_col);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
#define UTILS_H
|
||||
|
||||
#include "./ts_def.h"
|
||||
#include <chrono>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#define PCRE2_CODE_UNIT_WIDTH 8
|
||||
#define PCRE_WORKSPACE_SIZE 512
|
||||
@@ -63,4 +66,23 @@ void copy_to_clipboard(const char *text, size_t len);
|
||||
char *get_from_clipboard(uint32_t *out_len);
|
||||
uint32_t count_clusters(const char *line, size_t len, size_t from, size_t to);
|
||||
|
||||
template <typename Func, typename... Args>
|
||||
auto throttle(std::chrono::milliseconds min_duration, Func &&func,
|
||||
Args &&...args) {
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
if constexpr (std::is_void_v<std::invoke_result_t<Func, Args...>>) {
|
||||
std::invoke(std::forward<Func>(func), std::forward<Args>(args)...);
|
||||
} else {
|
||||
auto result =
|
||||
std::invoke(std::forward<Func>(func), std::forward<Args>(args)...);
|
||||
auto elapsed = std::chrono::steady_clock::now() - start;
|
||||
if (elapsed < min_duration)
|
||||
std::this_thread::sleep_for(min_duration - elapsed);
|
||||
return result;
|
||||
}
|
||||
auto elapsed = std::chrono::steady_clock::now() - start;
|
||||
if (elapsed < min_duration)
|
||||
std::this_thread::sleep_for(min_duration - elapsed);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user