Skip to content

Feature: auto collapse all chunks on load #96

Description

@ViscousPot

Describe the feature
It would be great to have a flag on the code_editor or controller that auto collapses all the chunks in a file before loading.

Why it's worth it
I was initially just looking to do this for convenience when looking at a particular file that is in an expected format, while using a custom ChunkAnalyzer. Basically to just hide the unimportant bits in a log file. But after implementing it, and then replacing the editor with a loading spinner while collapsing the chunks, the highlight analysis actually happened a lot faster.

I have to assume what happened was that the highlight analysis was held off until after everything was collapsed so it had less to analyse. So, could be helpful against this (#2), to reduce the initial load.

The code I'm using to collapse all the chunks (doubt it's the best way)

WidgetsBinding.instance.addPostFrameCallback((_) async {
  if (controller.text.isEmpty) return;
  chunksCollapsed = false;

  var chunkController = ReEditor.CodeChunkController(controller, LogsChunkAnalyzer());
  while (chunkController.value.isEmpty) {
    await Future.delayed(Duration(milliseconds: 100));
  }
  int offset = 0;

  for (final chunk in chunkController.value) {
    chunkController.collapse(chunk.index - offset);
    offset += max(0, chunk.end - chunk.index - 1);
  }
  
  chunksCollapsed = true;
  setState(() {});
});

and then in the UI

!chunksCollapsed
  ? Center(child: CircularProgressIndicator(color: Colors.white))
  : CodeEditor( ...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions