Skip to content

Commit

Permalink
jsx indent fix
Browse files Browse the repository at this point in the history
  • Loading branch information
fxbois committed May 26, 2017
1 parent 2ed2b26 commit 94de07b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
22 changes: 22 additions & 0 deletions issues/0882.jsx
@@ -0,0 +1,22 @@
import React, {Component} from 'react';
class Confirm extends Component {
render() {
const project = this.props.project;
return (
<Foo
someLongValue='x'
text={
<Text>
text
</Text>
}
/>
<div>
<OtherComponent/>
<OtherComponent class="toto"
{...props}
id="fr" />
</div>
)
}
}
13 changes: 13 additions & 0 deletions tests/test.jsx
Expand Up @@ -42,6 +42,19 @@ class Confirm extends Component {
</DefaultLayout>
)} />
)
},
render() {
const project = this.props.project;
return (
<Foo
someLongValue='x'
text={
<Text>
text
</Text>
}
/>
)
}
}

Expand Down
31 changes: 25 additions & 6 deletions web-mode.el
Expand Up @@ -3,7 +3,7 @@

;; Copyright 2011-2017 François-Xavier Bois

;; Version: 14.1.20
;; Version: 14.1.21
;; Author: François-Xavier Bois <fxbois AT Google Mail Service>
;; Maintainer: François-Xavier Bois
;; Package-Requires: ((emacs "23.1"))
Expand All @@ -24,7 +24,7 @@

;;---- CONSTS ------------------------------------------------------------------

(defconst web-mode-version "14.1.20"
(defconst web-mode-version "14.1.21"
"Web Mode version.")

;;---- GROUPS ------------------------------------------------------------------
Expand Down Expand Up @@ -4828,12 +4828,16 @@ another auto-completion with different ac-sources (e.g. ac-php)")
(defun web-mode-jsx-is-html (&optional pos)
(interactive)
(unless pos (setq pos (point)))
(let ((depth (get-text-property pos 'jsx-depth)))
(let (ret (depth (get-text-property pos 'jsx-depth)))
(cond
((or (null depth) (<= pos 2))
(setq pos nil))
((and (= depth 1) (get-text-property pos 'jsx-beg))
(setq pos nil))
((get-text-property pos 'tag-end)
(setq pos nil))
((get-text-property pos 'tag-attr-beg)
(setq pos nil))
((get-text-property pos 'jsx-beg)
(setq pos (null (get-text-property pos 'tag-beg))))
((setq pos (web-mode-jsx-depth-beginning-position pos))
Expand All @@ -4844,6 +4848,17 @@ another auto-completion with different ac-sources (e.g. ac-php)")
;;(message "is-html: %S (depth=%S)" pos depth)
pos))

(defun web-mode-jsx-is-expr (&optional pos)
(cond
((and (get-text-property pos 'jsx-beg)
(not (get-text-property pos 'tag-beg)))
nil)
(t
(setq pos (web-mode-jsx-depth-beginning-position pos))
(null (get-text-property pos 'tag-beg)))
) ;cond
)

(defun web-mode-jsx-depth-beginning-position (&optional pos target-depth)
(interactive)
(unless pos (setq pos (point)))
Expand Down Expand Up @@ -7095,6 +7110,7 @@ another auto-completion with different ac-sources (e.g. ac-php)")

;;(message "%S" language)
;;(message "curr-char=[%c] prev-char=[%c]\n%S" curr-char prev-char ctx)
;;(message "options=%S" options)

(cond

Expand Down Expand Up @@ -7219,8 +7235,12 @@ another auto-completion with different ac-sources (e.g. ac-php)")
((and (member language '("html" "xml" "javascript" "jsx"))
(get-text-property pos 'tag-type)
(not (get-text-property pos 'tag-beg))
(or (not (string= language "jsx"))
(string= options "is-html")))
;;(or (not (string= language "jsx"))
;; (string= options "is-html"))
(not (and (string= language "jsx")
(or (string= options "is-html")
(web-mode-jsx-is-expr pos))))
)
(when debug (message "I190(%S) attr-indent" pos))
(cond
((and (get-text-property pos 'tag-attr)
Expand Down Expand Up @@ -7249,7 +7269,6 @@ another auto-completion with different ac-sources (e.g. ac-php)")
((string-match-p "^/?>" curr-line)
(setq offset (current-column)))
(web-mode-attr-indent-offset

(setq offset (+ (current-column) web-mode-attr-indent-offset)))
((looking-at-p (concat web-mode-start-tag-regexp "[ ]*\n"))
(setq offset (+ (current-column) (or web-mode-attr-indent-offset web-mode-code-indent-offset))))
Expand Down

0 comments on commit 94de07b

Please sign in to comment.