codemirror / codemirror5

In-browser code editor (version 5, legacy)
http://codemirror.net/5/
MIT License
26.82k stars 4.97k forks source link

Searching across multiple CodeMirror instances #4282

Closed rgbkrk closed 8 years ago

rgbkrk commented 8 years ago

Are there hooks that would allow me to enable search/replace across multiple CodeMirror instances on a single page?

Let's say I have the following simple page with two CodeMirror instances:

const body = document.querySelector('body')

const title = document.createElement('h1')
title.textContent = 'This is a document with multiple CodeMirrors'
body.appendChild(title);

const area1 = document.createElement('textarea')
body.appendChild(area1)
const editor1 = CodeMirror.fromTextArea(area1, {
  lineNumbers: true,
})

const segway = document.createElement('h2')
segway.textContent = 'Moving on to another editor'
body.appendChild(segway)

const area2 = document.createElement('textarea')
body.appendChild(area2)
const editor2 = CodeMirror.fromTextArea(area2, {
  lineNumbers: true,
})

and that I've included

Each CodeMirror instance now has their own search handler when focused on the editor (triggered via ctrl/cmd-f). How could I implement search/replace that works across multiple CodeMirror instances?

There's at least a way to execute a find on each editor: editor.execCommand. I'm not seeing a way to pass through to it, or to query about what results are available.

CodePen with example code and imports

StackOverflow issue with (roughly) the same post

Issue on nteract

marijnh commented 8 years ago

Nope. You'll have to code that up yourself.

rgbkrk commented 8 years ago

I'm happy coding it up, I'm mostly unsure about how to access search across each instance. I suppose I need to look at this as if it's a new addon, following on from codemirror/addon/search/search?

fonsp commented 4 years ago

(The discussion was continued here: https://stackoverflow.com/questions/39812210/how-can-i-search-across-multiple-codemirror-instances)