Revert "Spruce up SkSL slide with a much nicer editor"

This reverts commit 88c5af7ecd72090b2d2eff2aec3a28c30c72a7fb.

Reason for revert: Various input bugs in the new editor make it somewhat unusable.

Original change's description:
> Spruce up SkSL slide with a much nicer editor
>
> Pulls in a new GitHub repo that implements a syntax-highlighting code
> editor ImGui widget.
>
> Change-Id: I968e5eb827c226259eaaad2996eeaad9de592e37
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/491444
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>

Change-Id: Ifa5bc87327785d107956201c4d866c7259006ec2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/492359
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/DEPS b/DEPS
index 95840a6..09f9f03 100644
--- a/DEPS
+++ b/DEPS
@@ -28,7 +28,6 @@
   "third_party/externals/harfbuzz"        : "https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git@3160789701463bcd822c26010da4de33c92c85d9",
   "third_party/externals/icu"             : "https://chromium.googlesource.com/chromium/deps/icu.git@a0718d4f121727e30b8d52c7a189ebf5ab52421f",
   "third_party/externals/imgui"           : "https://skia.googlesource.com/external/github.com/ocornut/imgui.git@55d35d8387c15bf0cfd71861df67af8cfbda7456",
-  "third_party/externals/ImGuiColorTextEdit" : "https://skia.googlesource.com/external/github.com/BalazsJako/ImGuiColorTextEdit.git@0a88824f7de8d0bd11d8419066caa7d3469395c4",
   "third_party/externals/libgifcodec"     : "https://skia.googlesource.com/libgifcodec@fd59fa92a0c86788dcdd84d091e1ce81eda06a77",
   "third_party/externals/libjpeg-turbo"   : "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git@24e310554f07c0fdb8ee52e3e708e4f3e9eb6e20",
   "third_party/externals/libpng"          : "https://skia.googlesource.com/third_party/libpng.git@386707c6d19b974ca2e3db7f5c61873813c6fe44",
diff --git a/third_party/imgui/BUILD.gn b/third_party/imgui/BUILD.gn
index 26308fb..dd1e50c 100644
--- a/third_party/imgui/BUILD.gn
+++ b/third_party/imgui/BUILD.gn
@@ -9,14 +9,10 @@
 import("../third_party.gni")
 
 third_party("imgui") {
-  public_include_dirs = [
-    "../externals/imgui",
-    "../externals/ImGuiColorTextEdit",
-  ]
+  public_include_dirs = [ "../externals/imgui" ]
   public_defines = [ "IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS" ]
 
   sources = [
-    "../externals/ImGuiColorTextEdit/TextEditor.cpp",
     "../externals/imgui/imconfig.h",
     "../externals/imgui/imgui.cpp",
     "../externals/imgui/imgui.h",
diff --git a/tools/viewer/SkSLSlide.cpp b/tools/viewer/SkSLSlide.cpp
index 2ed0a16..4a48079 100644
--- a/tools/viewer/SkSLSlide.cpp
+++ b/tools/viewer/SkSLSlide.cpp
@@ -14,33 +14,38 @@
 #include "include/sksl/SkSLDebugTrace.h"
 #include "src/core/SkEnumerate.h"
 #include "tools/Resources.h"
+#include "tools/viewer/Viewer.h"
 
 #include <algorithm>
 #include <cstdio>
-#include <regex>
 #include "imgui.h"
-#include "TextEditor.h"
 
 using namespace sk_app;
 
 ///////////////////////////////////////////////////////////////////////////////
 
+static int InputTextCallback(ImGuiInputTextCallbackData* data) {
+    if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) {
+        SkString* s = (SkString*)data->UserData;
+        SkASSERT(data->Buf == s->writable_str());
+        SkString tmp(data->Buf, data->BufTextLen);
+        s->swap(tmp);
+        data->Buf = s->writable_str();
+    }
+    return 0;
+}
+
 SkSLSlide::SkSLSlide() {
     // Register types for serialization
     fName = "SkSL";
 
-    // Prefix the code with some of the standard shadertoy inputs, by default:
-    fEditor.SetText(
-        "uniform float3 iResolution;\n"
-        "uniform float  iTime;\n"
-        "uniform float4 iMouse;\n"
-        "\n"
+    fSkSL =
+
         "uniform shader child;\n"
         "\n"
         "half4 main(float2 p) {\n"
         "    return child.eval(p);\n"
-        "}\n");
-    fEditor.SetShowWhitespaces(false);
+        "}\n";
 
     fCodeIsDirty = true;
 }
@@ -77,7 +82,14 @@
 }
 
 bool SkSLSlide::rebuild() {
-    std::string sksl = fEditor.GetText();
+    // Some of the standard shadertoy inputs:
+    SkString sksl;
+    if (fShadertoyUniforms) {
+        sksl = "uniform float3 iResolution;\n"
+               "uniform float  iTime;\n"
+               "uniform float4 iMouse;\n";
+    }
+    sksl.append(fSkSL);
 
     // It shouldn't happen, but it's possible to assert in the compiler, especially mid-edit.
     // To guard against losing your work, write out the shader to a backup file, then remove it
@@ -85,30 +97,16 @@
     constexpr char kBackupFile[] = "sksl.bak";
     FILE* backup = fopen(kBackupFile, "w");
     if (backup) {
-        fwrite(sksl.c_str(), 1, sksl.size(), backup);
+        fwrite(fSkSL.c_str(), 1, fSkSL.size(), backup);
         fclose(backup);
     }
-    auto [effect, errorText] = SkRuntimeEffect::MakeForShader(SkString(sksl.c_str()));
+    auto [effect, errorText] = SkRuntimeEffect::MakeForShader(sksl);
     if (backup) {
         std::remove(kBackupFile);
     }
 
-    fErrors.clear();
-    fEditor.SetErrorMarkers(fErrors);
-
     if (!effect) {
-        SkTArray<SkString> errorLines;
-        SkStrSplit(errorText.c_str(), "\n", &errorLines);
-        std::regex errorRegex("error: ([0-9]+): (.*)");
-        std::cmatch errorMatch;
-        for (const auto& line : errorLines) {
-            if (std::regex_match(line.c_str(), errorMatch, errorRegex)) {
-                int lineNum = std::atoi(errorMatch[1].str().c_str());
-                fErrors[lineNum].append(errorMatch[2].str());
-                fErrors[lineNum].append("\n");
-            }
-        }
-        fEditor.SetErrorMarkers(fErrors);
+        Viewer::ShaderErrorHandler()->compileError(sksl.c_str(), errorText.c_str());
         return false;
     }
 
@@ -127,11 +125,17 @@
 void SkSLSlide::draw(SkCanvas* canvas) {
     canvas->clear(SK_ColorWHITE);
 
-    ImGui::Begin("SkSL");
+    ImGui::Begin("SkSL", nullptr, ImGuiWindowFlags_AlwaysVerticalScrollbar);
 
     // Edit box for shader code
-    fEditor.Render("Code", ImVec2(0, 500));
-    if (fEditor.IsTextChanged()) {
+    ImGuiInputTextFlags flags = ImGuiInputTextFlags_CallbackResize;
+    ImVec2 boxSize(-1.0f, ImGui::GetTextLineHeight() * 30);
+    if (ImGui::InputTextMultiline("Code", fSkSL.writable_str(), fSkSL.size() + 1, boxSize, flags,
+                                  InputTextCallback, &fSkSL)) {
+        fCodeIsDirty = true;
+    }
+
+    if (ImGui::Checkbox("ShaderToy Uniforms (iResolution/iTime/iMouse)", &fShadertoyUniforms)) {
         fCodeIsDirty = true;
     }
 
@@ -167,15 +171,15 @@
 
     for (const auto& v : fEffect->uniforms()) {
         char* data = fInputs.get() + v.offset;
-        if (v.name.equals("iResolution") && v.type == SkRuntimeEffect::Uniform::Type::kFloat3) {
+        if (v.name.equals("iResolution")) {
             memcpy(data, &fResolution, sizeof(fResolution));
             continue;
         }
-        if (v.name.equals("iTime") && v.type == SkRuntimeEffect::Uniform::Type::kFloat) {
+        if (v.name.equals("iTime")) {
             memcpy(data, &fSeconds, sizeof(fSeconds));
             continue;
         }
-        if (v.name.equals("iMouse") && v.type == SkRuntimeEffect::Uniform::Type::kFloat4) {
+        if (v.name.equals("iMouse")) {
             memcpy(data, &fMousePos, sizeof(fMousePos));
             continue;
         }
diff --git a/tools/viewer/SkSLSlide.h b/tools/viewer/SkSLSlide.h
index 3c5a685..d6a1de3 100644
--- a/tools/viewer/SkSLSlide.h
+++ b/tools/viewer/SkSLSlide.h
@@ -10,7 +10,6 @@
 
 #include "include/core/SkM44.h"
 #include "include/effects/SkRuntimeEffect.h"
-#include "third_party/externals/ImGuiColorTextEdit/TextEditor.h"
 #include "tools/viewer/Slide.h"
 
 class SkSLSlide : public Slide {
@@ -35,9 +34,7 @@
 private:
     bool rebuild();
 
-    TextEditor fEditor;
-    TextEditor::ErrorMarkers fErrors;
-
+    SkString fSkSL;
     bool fCodeIsDirty;
     sk_sp<SkRuntimeEffect> fEffect;
     SkAutoTMalloc<char> fInputs;
@@ -55,6 +52,7 @@
     SkV3 fResolution = { 1, 1, 1 };
     SkV4 fMousePos;
     int fTraceCoord[2] = {64, 64};
+    bool fShadertoyUniforms = true;
 
     // Named shaders that can be selected as inputs
     SkTArray<std::pair<const char*, sk_sp<SkShader>>> fShaders;