-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update/minor_major
- Loading branch information
Showing
32 changed files
with
812 additions
and
587 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
client/src/main/scala/com.olegych.scastie.client/components/EmbeddedOverlay.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../src/main/scala/com.olegych.scastie.client/components/editor/DebouncingCapabilities.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.olegych.scastie.client.components.editor | ||
|
||
import typings.codemirrorState.mod._ | ||
import typings.codemirrorView.mod._ | ||
|
||
import scala.concurrent.duration._ | ||
import scala.scalajs.js.timers._ | ||
|
||
import scalajs.js | ||
import EditorTextOps._ | ||
|
||
|
||
trait DebouncingCapabilities { | ||
type OnChange = (String, EditorView) => Unit | ||
|
||
private val onChangeFacet: Facet[OnChange, OnChange] = Facet.define[OnChange, OnChange] { | ||
FacetConfig[OnChange, OnChange]().setCombine(input => over(input.toSeq)) | ||
} | ||
|
||
private def debounce(fn: OnChange): OnChange = { | ||
var timeout: js.UndefOr[js.timers.SetTimeoutHandle] = js.undefined | ||
|
||
(code: String, view: EditorView) => { | ||
val tokenLength = view | ||
.lineBeforeCursor | ||
.reverseIterator | ||
.takeWhile(c => !c.isWhitespace || c == '.') | ||
.length | ||
|
||
tokenLength match { | ||
case 0 => fn(code, view) | ||
case _ => | ||
timeout.foreach(clearTimeout) | ||
timeout = setTimeout(250.millis) { | ||
fn(code, view) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private def over(functions: Seq[OnChange]): OnChange = { | ||
(code: String, view: EditorView) => functions.foreach(f => f(code, view)) | ||
} | ||
|
||
protected def onChangeCallback(onChange: OnChange): Extension = { | ||
val debouncedOnChange = debounce(onChange) | ||
|
||
js.Array[Any]( | ||
onChangeFacet.of(debouncedOnChange), | ||
EditorView.updateListener.of(viewUpdate => { | ||
if (viewUpdate.docChanged) { | ||
val content = viewUpdate.state.sliceDoc() | ||
val onChange = viewUpdate.state.facet[OnChange](onChangeFacet.asInstanceOf[Facet[Any, OnChange]]) | ||
onChange(content, viewUpdate.view) | ||
} | ||
}) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
client/src/main/scala/com.olegych.scastie.client/components/editor/EditorTextOps.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.olegych.scastie.client.components.editor | ||
|
||
import typings.codemirrorView.mod._ | ||
|
||
|
||
object EditorTextOps { | ||
val regex = """\.?\w+""".r | ||
|
||
implicit class EditorTextOpsOps(view: EditorView) { | ||
def lineBeforeCursor: String = { | ||
val pos = view.state.selection.main.from | ||
val line = view.state.doc.lineAt(pos) | ||
val start = Math.max(line.from, pos - 250) | ||
line.text.slice(start.toInt - line.from.toInt, pos.toInt - line.from.toInt) | ||
} | ||
|
||
def matchesPreviousToken(previousToken: String): Boolean = { | ||
val matchedString = regex.findAllIn(lineBeforeCursor).iterator.toSeq | ||
matchedString.lastOption.exists(_.startsWith(previousToken)) | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.