Path: blob/main/internal/messages/composer/input_gtksource.go
366 views
//go:build !nogtksource && !windows12package composer34import (5"log/slog"67"github.com/diamondburned/gotk4/pkg/gtk/v4"8"github.com/diamondburned/gotkit/app"9"github.com/diamondburned/gotkit/app/prefs"10"libdb.so/gotk4-sourceview/pkg/gtksource/v5"11"libdb.so/gotk4-spelling/pkg/spelling"12)1314var spellCheck = prefs.NewBool(true, prefs.PropMeta{15Name: "Spell Check",16Section: "Composer",17Description: "Enable spell checking in the composer.",18})1920func init() {21app.Hook(func(*app.Application) {22gtksource.Init()23spelling.Init()24})25}2627func initializeInput() initializedInput {28languageManager := gtksource.LanguageManagerGetDefault()29spellChecker := spelling.CheckerGetDefault()3031buffer := gtksource.NewBuffer(nil)3233// Set up the buffer's highlighting language.34markdownLanguage := languageManager.Language("markdown")35if markdownLanguage != nil {36buffer.SetLanguage(markdownLanguage)37} else {38slog.Warn(39"language 'markdown' not found in gtksource, not setting one",40"languages", languageManager.LanguageIDs())41}4243// Set up the buffer's spell checking.44spellingAdapter := spelling.NewTextBufferAdapter(buffer, spellChecker)45spellingAdapter.SetEnabled(spellCheck.Value())46spellingAdapter.NotifyProperty("enabled", func() {47nowEnabled := spellingAdapter.Enabled()48if spellCheck.Value() != nowEnabled {49spellCheck.Publish(nowEnabled)50}51})5253view := gtk.NewTextViewWithBuffer(&buffer.TextBuffer)54view.AddCSSClass("composer-input-with-gtksource")55view.SetExtraMenu(spellingAdapter.MenuModel())56view.InsertActionGroup("spelling", spellingAdapter)5758return initializedInput{59View: view,60Buffer: &buffer.TextBuffer,61}62}636465