1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:47:34 +00:00

Spreadsheet: Add support for copying ranges of cells to other cells

Now the entire range is copied to the area around the target cell,
translating the current cursor to the target.
This commit is contained in:
AnotherTest 2020-11-07 23:18:41 +03:30 committed by Andreas Kling
parent 7878596532
commit e99c2261e3
8 changed files with 187 additions and 53 deletions

View file

@ -51,6 +51,11 @@ public:
Cell* from_url(const URL&);
const Cell* from_url(const URL& url) const { return const_cast<Sheet*>(this)->from_url(url); }
Optional<Position> position_from_url(const URL& url) const;
/// Resolve 'offset' to an absolute position assuming 'base' is at 'offset_base'.
/// Effectively, "Walk the distance between 'offset' and 'offset_base' away from 'base'".
Position offset_relative_to(const Position& base, const Position& offset, const Position& offset_base) const;
JsonObject to_json() const;
static RefPtr<Sheet> from_json(const JsonObject&, Workbook&);
@ -87,6 +92,14 @@ public:
size_t row_count() const { return m_rows; }
size_t column_count() const { return m_columns.size(); }
const Vector<String>& columns() const { return m_columns; }
const String& column(size_t index)
{
for (size_t i = column_count(); i < index; ++i)
add_column();
ASSERT(column_count() > index);
return m_columns[index];
}
const String& column(size_t index) const
{
ASSERT(column_count() > index);
@ -105,6 +118,8 @@ public:
const Workbook& workbook() const { return m_workbook; }
void copy_cells(Vector<Position> from, Vector<Position> to, Optional<Position> resolve_relative_to = {});
private:
explicit Sheet(Workbook&);
explicit Sheet(const StringView& name, Workbook&);