Set several lines as active

Is there any way to set several lines as active in different location?

Example: we have 10 lines. Need select 1, 5, 6, 8, 9 and 10 lines. How to do that?

It can be achieved by dispatching a selection

ranges = [SelectionRange.from .... ]
view?.dispatch({
  selection:EditorSelection.create(ranges),
  });

Thank you very much for all three answers of my topics!

You’re welcome, I happen to have dealt with it