                              (.warn js/console
                                     (str "Failed to lookup hyphenation patterns for word: " details)))))
 
-(defn hyphenation-pattern [{:keys [word hyphenation] :as pattern}]
+(defn hyphenation-pattern [{:keys [word hyphenation]}]
   [:tr
    [:td word]
-   [:td hyphenation]
-   [:td
-    [:div.btn-group
-     [:button.btn.btn-default
-      [:span.glyphicon.glyphicon-edit {:aria-hidden true}] " Edit"]
-     [:button.btn.btn-default
-      {:on-click #(remove-hyphenation-pattern! pattern)}
-      [:span.glyphicon.glyphicon-trash {:aria-hidden true}] " Delete"]]]])
+   [:td hyphenation]])
+
+(defn- hyphenation-valid? [s]
+  (and (not (string/blank? s))
+       (string/includes? s "-")
+       (re-matches #"[a-z\xDF-\xFF-]+" s)))
+
+(defn hyphenation-pattern-editable-item [{:keys [hyphenation]}]
+  (let [editing (reagent/atom false)
+        new-hyphenation (reagent/atom hyphenation)]
+    (fn [{:keys [word hyphenation] :as pattern}]
+      (if-not @editing
+        [:tr
+         [:td word]
+         [:td hyphenation]
+         [:td
+          [:div.btn-group
+           [:button.btn.btn-default
+            {:on-click #(reset! editing true)}
+            [:span.glyphicon.glyphicon-edit {:aria-hidden true}] " Edit"]
+           [:button.btn.btn-default
+            {:on-click #(remove-hyphenation-pattern! pattern)}
+            [:span.glyphicon.glyphicon-trash {:aria-hidden true}] " Delete"]]]]
+        [:tr
+         [:td word]
+         [:td
+          [:input.form-control
+           {:type "text"
+            :auto-focus true
+            :on-change #(reset! new-hyphenation (-> % .-target .-value))
+            :on-key-down #(case (.-which %)
+                            27 (do
+                                 (reset! new-hyphenation hyphenation)
+                                 (reset! editing false))
+                            nil)
+            :value @new-hyphenation}]]
+         [:td
+          [:div.btn-group
+           [:button.btn.btn-default
+            {:on-click #(do (when (hyphenation-valid? @new-hyphenation)
+                              (add-hyphenation-pattern!
+                               (assoc pattern :hyphenation @new-hyphenation)))
+                            (reset! editing false))}
+            [:span.glyphicon.glyphicon-ok {:aria-hidden true}] " Save"]
+           [:button.btn.btn-default
+            {:on-click #(do
+                          (reset! new-hyphenation hyphenation)
+                          (reset! editing false))}
+            [:span.glyphicon.glyphicon-remove {:aria-hidden true}] " Cancel"]]]]))))
 
 (defn word-field []
   [:div.form-group

      (for [[word pattern] (:hyphenations @app-state)]
        ^{:key word} [hyphenation-pattern pattern])]]]])

;; -------------------------
;; Views

(defn home-page []
  [hyphenation-list])

(defn about-page []
  [:div [:h2 "About hyphen-keeper"]
   [:div [:a {:href "/"} "go to the home page"]]])

(defn current-page []
  [:div [(session/get :current-page)]])

                  (load-hyphenation-patterns! @spelling @word))
     :on-blur #(lookup-hyphenation-pattern! @spelling @word)}]])

(defn hyphenation-field []
  (let [label "Corrected Hyphenation"
        valid? (or (string/blank? @hyphenation) (hyphenation-valid? @hyphenation))
