home/src/user_interface.hh
Johannes Altmanninger b2cf74bb4a Implement bracketed paste
Text pasted into Kakoune's normal mode is interpreted as command
sequence, which is probably never what the user wants. Text
pasted during insert mode will be inserted fine but may trigger
auto-indentation hooks which is likely not what users want.

Bracketed paste is pair of escape codes sent by terminals that allow
applications to distinguish between pasted text and typed text.

Let's use this feature to always insert pasted text verbatim, skipping
keymap lookup and the InsertChar hook. In future, we could add a
dedicated Paste hook.

We need to make a decision on whether to paste before or after the
selection. I chose "before" because that's what I'm used to.

TerminalUI::set_on_key has

	EventManager::instance().force_signal(0);

I'm not sure if we want the same for TerminalUI::set_on_paste?
I assume it doesn't matter because they are always called in tandem.

Closes #2465
2023-03-11 16:21:57 +01:00

91 lines
2.1 KiB
C++

#ifndef user_interface_hh_INCLUDED
#define user_interface_hh_INCLUDED
#include "array_view.hh"
#include "hash_map.hh"
#include <functional>
namespace Kakoune
{
class String;
class DisplayBuffer;
class DisplayLine;
using DisplayLineList = Vector<DisplayLine, MemoryDomain::Display>;
struct DisplayCoord;
struct Face;
struct Key;
enum class MenuStyle
{
Prompt,
Search,
Inline
};
enum class InfoStyle
{
Prompt,
Inline,
InlineAbove,
InlineBelow,
MenuDoc,
Modal
};
enum class EventMode;
enum class CursorMode
{
Prompt,
Buffer,
};
using OnKeyCallback = std::function<void(Key key)>;
using OnPasteCallback = std::function<void(StringView content)>;
class UserInterface
{
public:
virtual ~UserInterface() = default;
virtual bool is_ok() const = 0;
virtual void menu_show(ConstArrayView<DisplayLine> choices,
DisplayCoord anchor, Face fg, Face bg,
MenuStyle style) = 0;
virtual void menu_select(int selected) = 0;
virtual void menu_hide() = 0;
virtual void info_show(const DisplayLine& title,
const DisplayLineList& content,
DisplayCoord anchor, Face face,
InfoStyle style) = 0;
virtual void info_hide() = 0;
virtual void draw(const DisplayBuffer& display_buffer,
const Face& default_face,
const Face& padding_face) = 0;
virtual void draw_status(const DisplayLine& status_line,
const DisplayLine& mode_line,
const Face& default_face) = 0;
virtual DisplayCoord dimensions() = 0;
virtual void set_cursor(CursorMode mode, DisplayCoord coord) = 0;
virtual void refresh(bool force) = 0;
virtual void set_on_key(OnKeyCallback callback) = 0;
virtual void set_on_paste(OnPasteCallback callback) = 0;
using Options = HashMap<String, String, MemoryDomain::Options>;
virtual void set_ui_options(const Options& options) = 0;
};
}
#endif // user_interface_hh_INCLUDED