mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:57:44 +00:00
Spreadsheet: Implement infinit-scroll for columns
This naturally also implements multi-char columns, and also integrates it into the js runtime (such columns can be named in ranges too).
This commit is contained in:
parent
f6ae4edbd2
commit
474453244b
7 changed files with 233 additions and 50 deletions
|
@ -83,6 +83,8 @@ void SheetGlobalObject::initialize()
|
|||
GlobalObject::initialize();
|
||||
define_native_function("parse_cell_name", parse_cell_name, 1);
|
||||
define_native_function("current_cell_position", current_cell_position, 0);
|
||||
define_native_function("column_arithmetic", column_arithmetic, 2);
|
||||
define_native_function("column_index", column_index, 1);
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::parse_cell_name)
|
||||
|
@ -137,6 +139,82 @@ JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::current_cell_position)
|
|||
return object;
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_index)
|
||||
{
|
||||
if (vm.argument_count() != 2) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, "Expected exactly one argument to column_index()");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto column_name = vm.argument(0);
|
||||
if (!column_name.is_string()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "String");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto& column_name_str = column_name.as_string().string();
|
||||
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return JS::js_null();
|
||||
|
||||
if (StringView("SheetGlobalObject") != this_object->class_name()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "SheetGlobalObject");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
auto& sheet = sheet_object->m_sheet;
|
||||
auto column_index = sheet.column_index(column_name_str);
|
||||
if (!column_index.has_value()) {
|
||||
vm.throw_exception(global_object, JS::TypeError::create(global_object, String::formatted("'{}' is not a valid column", column_name_str)));
|
||||
return {};
|
||||
}
|
||||
|
||||
return JS::Value((i32)column_index.value());
|
||||
}
|
||||
|
||||
JS_DEFINE_NATIVE_FUNCTION(SheetGlobalObject::column_arithmetic)
|
||||
{
|
||||
if (vm.argument_count() != 2) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, "Expected exactly two arguments to column_arithmetic()");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto column_name = vm.argument(0);
|
||||
if (!column_name.is_string()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "String");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto& column_name_str = column_name.as_string().string();
|
||||
|
||||
auto offset = vm.argument(1).to_number(global_object);
|
||||
if (!offset.is_number())
|
||||
return {};
|
||||
|
||||
auto offset_number = offset.as_i32();
|
||||
|
||||
auto* this_object = vm.this_value(global_object).to_object(global_object);
|
||||
if (!this_object)
|
||||
return JS::js_null();
|
||||
|
||||
if (StringView("SheetGlobalObject") != this_object->class_name()) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotA, "SheetGlobalObject");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto sheet_object = static_cast<SheetGlobalObject*>(this_object);
|
||||
auto& sheet = sheet_object->m_sheet;
|
||||
auto new_column = sheet.column_arithmetic(column_name_str, offset_number);
|
||||
if (!new_column.has_value()) {
|
||||
vm.throw_exception(global_object, JS::TypeError::create(global_object, String::formatted("'{}' is not a valid column", column_name_str)));
|
||||
return {};
|
||||
}
|
||||
|
||||
return JS::js_string(vm, new_column.release_value());
|
||||
}
|
||||
|
||||
WorkbookObject::WorkbookObject(Workbook& workbook)
|
||||
: JS::Object(*JS::Object::create_empty(workbook.global_object()))
|
||||
, m_workbook(workbook)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue