mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:57:35 +00:00
HexEditor: Add annotations system
Allow the user to highlight sections of the edited document, giving them arbitrary background colors. These annotations can be created from a selection, or by manually specifying the start and end offsets. Annotations can be edited or deleted by right-clicking them. Any color can be used for the background. Dark colors automatically make the text white for easier readability. When creating a new annotation, we use whatever color the user last picked as this is slightly more likely to be the one they want. Icons contributed by Cubic Love. Co-authored-by: Cubic Love <7754483+cubiclove@users.noreply.github.com>
This commit is contained in:
parent
1168e46c1d
commit
cbd28c9110
13 changed files with 378 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Arne Elster <arne@elster.li>
|
||||
* Copyright (c) 2024, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -14,9 +15,18 @@
|
|||
#include <AK/WeakPtr.h>
|
||||
#include <LibCore/Forward.h>
|
||||
#include <LibGUI/Command.h>
|
||||
#include <LibGfx/Color.h>
|
||||
|
||||
constexpr Duration COMMAND_COMMIT_TIME = Duration::from_milliseconds(400);
|
||||
|
||||
struct Annotation {
|
||||
size_t start_offset { 0 };
|
||||
size_t end_offset { 0 };
|
||||
Gfx::Color background_color { Color::from_argb(0xfffce94f) };
|
||||
|
||||
bool operator==(Annotation const& other) const = default;
|
||||
};
|
||||
|
||||
class HexDocument : public Weakable<HexDocument> {
|
||||
public:
|
||||
enum class Type {
|
||||
|
@ -38,8 +48,14 @@ public:
|
|||
virtual bool is_dirty() const;
|
||||
virtual void clear_changes() = 0;
|
||||
|
||||
ReadonlySpan<Annotation> annotations() const { return m_annotations; }
|
||||
void add_annotation(Annotation);
|
||||
void delete_annotation(Annotation const&);
|
||||
Optional<Annotation&> closest_annotation_at(size_t position);
|
||||
|
||||
protected:
|
||||
HashMap<size_t, u8> m_changes;
|
||||
Vector<Annotation> m_annotations;
|
||||
};
|
||||
|
||||
class HexDocumentMemory final : public HexDocument {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue