Verified Commit e1ab372d authored by 殊海夕音's avatar 殊海夕音

Merge branch 'replace-modal' into develop

parents 78799a4e 49936e02
......@@ -23,6 +23,27 @@ module Editor2
Element.find('#document-editor>.content-view').append(@contents.dom_element)
contents.dispatcher = @dispatcher
# 置換ダイアログ
Element.find('#replace-dialog').tap do |d|
d.find('button.ok').on(:click) do
from = d.find('.from-str').value
to = d.find('.to-str').value
@dispatcher.dispatch(
Action.new(
:operation => :replace,
:payload => {:from => from, :to => to}
)
)
end
d.find('button').on(:click) do
@shortcut.resume
d.find('.from-str').value = ''
d.find('.to-str').value = ''
end
end
# 設定ダイアログ
Element.find('#config-dialog').tap do |d|
d.find('input[name="markup"]').tap do |i|
......
......@@ -2,23 +2,36 @@ module Editor2
class Shortcut
def initialize(editor)
@editor = editor
@set = ::Shortcut::Set.new
::Shortcut.add('Enter') { enter_key } # 編集
::Shortcut.add('esc', 'disable_in_input' => false) { escape_key } # 編集終了
::Shortcut.add('Ctrl+Alt+n', 'disable_in_input' => false) { mod_alt_n_key } # 新規追加
::Shortcut.add('Ctrl+Delete') { mod_del_key } # 削除
::Shortcut.add('Tab', 'disable_in_input' => false) { tab_key} # カーソルを次へ
::Shortcut.add('Shift+Tab', 'disable_in_input' => false) { shift_tab_key } # カーソルを前へ
@set.add('Enter') { enter_key } # 編集
@set.add('esc', 'disable_in_input' => false) { escape_key } # 編集終了
@set.add('Ctrl+Alt+n', 'disable_in_input' => false) { mod_alt_n_key } # 新規追加
@set.add('Ctrl+Delete') { mod_del_key } # 削除
@set.add('Tab', 'disable_in_input' => false) { tab_key} # カーソルを次へ
@set.add('Shift+Tab', 'disable_in_input' => false) { shift_tab_key } # カーソルを前へ
::Shortcut.add('Up') { up_key } # 上へ
::Shortcut.add('Down') { down_key } # 下へ
::Shortcut.add('Left') { left_key } # 葉を閉じる
::Shortcut.add('Right') { right_key } # 葉を開く
@set.add('Up') { up_key } # 上へ
@set.add('Down') { down_key } # 下へ
@set.add('Left') { left_key } # 葉を閉じる
@set.add('Right') { right_key } # 葉を開く
::Shortcut.add('Ctrl+Up') { mod_up_key } # 上の葉と入れ替え
::Shortcut.add('Ctrl+Down') { mod_down_key } # 下の葉と入れ替え
::Shortcut.add('Ctrl+Left') { mod_left_key } # 1段上げる
::Shortcut.add('Ctrl+Right') { mod_right_key } # 1段下げる
@set.add('Ctrl+Up') { mod_up_key } # 上の葉と入れ替え
@set.add('Ctrl+Down') { mod_down_key } # 下の葉と入れ替え
@set.add('Ctrl+Left') { mod_left_key } # 1段上げる
@set.add('Ctrl+Right') { mod_right_key } # 1段下げる
@set.add('Ctrl+Shift+f') { mod_shift_f_key } # 置換
@set.resume
end
def suspend
@set.suspend
end
def resume
@set.resume
end
private
......@@ -186,5 +199,10 @@ module Editor2
)
end
end
def mod_shift_f_key
Element.find('#replace-dialog-open').trigger(:click)
@set.suspend
end
end
end
......@@ -50,6 +50,11 @@ module Editor2
end
end
def scan(&block)
block.call(self)
children.map{|c| c.scan{|c1| block.call(c1) } }
end
def to_h
{
:id => @id,
......@@ -104,6 +109,17 @@ module Editor2
end
def dispatch(*actions)
apply_actions(actions)
emit(actions)
end
def emit(processed_actions = [])
# サブスクライバに変更済みの文書を与える
@subscribers.each{|s| s.apply(stored_document, processed_actions) }
end
private
def apply_actions(actions)
actions.each do |action|
target =
if action.target
......@@ -145,6 +161,15 @@ module Editor2
@version = action.payload[:version] if action.payload.keys.include?(:version)
end
when :replace
from = action.payload[:from]
to = action.payload[:to]
@document.scan do |leaf|
leaf.title = leaf.title.gsub(from, to) if leaf.title
leaf.body = leaf.body.gsub(from, to) if leaf.body
end
when :remove
if target
if target.parent
......@@ -161,13 +186,6 @@ module Editor2
raise "unknown action: #{action.operation}"
end
end
emit(actions)
end
def emit(processed_actions = [])
# サブスクライバに変更済みの文書を与える
@subscribers.each{|s| s.apply(stored_document, processed_actions) }
end
end
end
......@@ -55,6 +55,7 @@ Document.ready? do
trigger.on('click') do
modal.effect(:fade_in)
Element.find('.mdl-layout__drawer,.mdl-layout__obfuscator').remove_class('is-visible')
modal.find('input[type="text"]').first.tap{|i| i.focus if i }
false
end
......
......@@ -12,4 +12,32 @@ module Shortcut
`shortcut.add(#{keys}, function(){#{yield}}, #{options.to_n})`
end
end
def self.remove(keys)
`shortcut.remove(#{keys})`
end
class Set
def initialize
@settings = []
end
def add(keys, options = {'disable_in_input' => true}, &block)
@settings.push(
:keys => keys,
:options => options,
:block => block
)
end
def suspend
@settings.each{|s| ::Shortcut.remove(s[:keys]) }
end
def resume
@settings.each do |s|
::Shortcut.add(s[:keys], s[:options], &s[:block])
end
end
end
end
......@@ -26,6 +26,11 @@
<%= hidden_field_tag :writable, @document.writable?.to_json, :id => 'document-writable' %>
<% content_for(:navigation1) do %>
<%= link_to '#', :class => 'mdl-navigation__link modal-trigger', :data => {:modal_selector => '#replace-dialog'}, :id => 'replace-dialog-open' do %>
<i class="material-icons">find_replace</i>
置換
<% end %>
<%= link_to '#', :class => 'mdl-navigation__link modal-trigger', :data => {:modal_selector => '#config-dialog'} do %>
<i class="material-icons">settings</i>
設定
......@@ -145,6 +150,29 @@
</div>
</div>
<div class="modal-card" id="replace-dialog">
<div class="modal-container">
<div class="mdl-card mdl-shadow--2dp">
<div class="mdl-card__supporting-text">
<div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input from-str" type="text" value="">
<label class="mdl-textfield__label">検索する文字列</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
<input class="mdl-textfield__input to-str" type="text" value="">
<label class="mdl-textfield__label">置換後の文字列</label>
</div>
</div>
<div class="mdl-dialog__actions">
<button type="button" class="mdl-button ok close">置換</button>
<button type="button" class="mdl-button cancel close">閉じる</button>
</div>
</div>
</div>
</div>
</div>
<dialog class="mdl-dialog" id="dialog-confirm">
<h4 class="mdl-dialog__title"></h4>
<div class="mdl-dialog__content"></div>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment